Navigation Menu

Skip to content

Commit

Permalink
Merge 08aad54 into 01c992a
Browse files Browse the repository at this point in the history
  • Loading branch information
sudarsan-surendralal committed May 8, 2019
2 parents 01c992a + 08aad54 commit 604d509
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pyiron/vasp/base.py
Expand Up @@ -454,6 +454,24 @@ def from_directory(self, directory):
else:
structure = vp_new.get_initial_structure()
self.structure = structure
# Read initial magnetic moments from the INCAR file and set it to the structure
magmom_loc = np.array(self.input.incar._dataset["Parameter"]) == "MAGMOM"
if any(magmom_loc):
init_moments = list()
try:
value = np.array(self.input.incar._dataset["Value"])[magmom_loc][0]
if "*" not in value:
init_moments = np.array([float(val) for val in value.split()])
else:
# Values given in "number_of_atoms*value" format
init_moments = np.hstack(([int(val.split("*")[0]) * [float(val.split("*")[1])] for val in value.split()]))
except (ValueError, IndexError, TypeError):
self.logger.warn("Unable to parse initial magnetic moments from the INCAR file")
if len(init_moments) == len(self.structure):
self.structure.set_initial_magnetic_moments(init_moments)
else:
self.logger.warn("Inconsistency during parsing initial magnetic moments from the INCAR file")

self._write_chemical_formular_to_database()
self._import_directory = directory
self.status.collect = True
Expand Down
1 change: 1 addition & 0 deletions tests/static/vasp_test_files/full_job_sample/INCAR
Expand Up @@ -3,3 +3,4 @@ PREC=Accurate
ALGO=Fast
ENCUT=250
LREAL=False
MAGMOM=2*-1
2 changes: 2 additions & 0 deletions tests/vasp/test_vasp_import.py
@@ -1,4 +1,5 @@
import unittest
import numpy as np
import os
from pyiron.project import Project
from pyiron.vasp.vasp import Vasp
Expand All @@ -24,6 +25,7 @@ def test_import(self):
ham = self.project.load('full_job_sample')
self.assertTrue(isinstance(ham, Vasp))
self.assertEqual(ham.get_nelect(), 16)
self.assertTrue(np.array_equal(ham.structure.get_initial_magnetic_moments(), [-1, -1]))


if __name__ == '__main__':
Expand Down

0 comments on commit 604d509

Please sign in to comment.