Skip to content

Commit b871f12

Browse files
committed
Improvements to vasp jobs (re)launching
1. Added correct handling of partial hydrogen atoms (e.g. H.75) 2. Fixed selective dynamics so that the property is retained when launching a vasp job 3. Fixed the infamous float number of nodes error with an integer division
1 parent 9f3e6ee commit b871f12

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

src/pylada/crystal/read.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,23 @@ def poscar(path="POSCAR", types=None):
8989
for i in line:
9090
if not re.match(r"[A-Z][a-z]?", i):
9191
is_vasp_5 = False
92-
break
92+
break
9393
if is_vasp_5:
9494
text_types = deepcopy(line)
95-
if types is not None and not set(text_types).issubset(set(types)):
96-
raise error.ValueError("Unknown species in poscar: {0} not in {1}."
97-
.format(text_types, types))
95+
96+
if types is not None:
97+
# If partial H (e.g. H.75) are specified they will replace H
98+
# in the order they were specified
99+
for s in types:
100+
if s[0] == "H" and "." in s:
101+
for i,c in enumerate(text_types):
102+
if c == "H":
103+
text_types[i] = s
104+
break
105+
106+
if not set(text_types).issubset(set(types)):
107+
raise error.ValueError("Unknown species in poscar: {0} not in {1}."
108+
.format(text_types, types))
98109
types = text_types
99110
line = poscar.readline().split()
100111
if types is None:

src/pylada/ipython/launch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def mppalloc(job):
167167
""" Returns number of processes for this job. """
168168
natom = len(job.structure) # number of atoms.
169169
# Round down to a multiple of ppn
170-
nnode = max(1, natom / event.ppn)
170+
nnode = max(1, natom // event.ppn)
171171
nproc = nnode * event.ppn
172172
return nproc
173173
logger.info("launch/init: mppalloc b: %s" % mppalloc)

src/pylada/vasp/extract/base.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,12 @@ def structure(self):
269269
""" Greps structure and total energy from OUTCAR. """
270270
if self.nsw == 0 or self.ibrion == -1:
271271
return self.initial_structure
272-
272+
273273
try:
274274
result = self._contcar_structure
275275
except:
276276
result = self._grep_structure
277-
277+
278278
# tries to find adequate name for structure.
279279
try:
280280
name = self.system
@@ -329,6 +329,7 @@ def structure(self):
329329
else:
330330
for force, atom in zip(forces, result):
331331
atom.force = force
332+
332333
return result
333334

334335
@property
@@ -447,7 +448,7 @@ def _contcar_structure(self):
447448
""" Greps structure from CONTCAR. """
448449
from ...crystal import read
449450
from quantities import eV
450-
451+
451452
result = read.poscar(self.__contcar__(), self.species)
452453
result.energy = float(self.total_energy.rescale(eV)) if self.is_dft else 0e0
453454
return result
@@ -470,8 +471,21 @@ def ions_per_specie(self):
470471
@property
471472
@make_cached
472473
def species(self):
474+
import re
473475
""" Greps species from OUTCAR. """
474-
return [ u.group(1) for u in self._search_OUTCAR(r"""VRHFIN\s*=\s*(\S+)\s*:""") ]
476+
result = []
477+
for u in self._search_OUTCAR(r"""VRHFIN\s*=\s*(.*)$"""):
478+
atom = u[1].split(":")[0].strip()
479+
match = re.search(r"Z\s*=\s*(\S+)", u[1])
480+
if match is None:
481+
result.append(atom)
482+
else:
483+
result.append(atom + ("%3.2f"%(eval(match[1]))).strip(" 0"))
484+
485+
# return [ u.group(1) for u in self._search_OUTCAR(r"""VRHFIN\s*=\s*(\S+)\s*:""") ]
486+
# return [ u.group(1) for u in self._search_OUTCAR(r"""TITEL\s*=\s*\S*\s*(\S+)""") ]
487+
488+
return result
475489

476490
@property
477491
@make_cached

src/pylada/vasp/functional.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def __init__(self, copy=None, species=None, kpoints=None, **kwargs):
304304
305305
.. _CONTCAR: http://cms.mpi.univie.ac.at/vasp/guide/node60.html
306306
"""
307-
self.isym = ChoiceKeyword(values=list(range(-1, 3)))
307+
self.isym = ChoiceKeyword(values=list(range(-1, 4)))
308308
""" Symmetry scheme.
309309
310310
.. seealso:: ISYM_
@@ -1017,8 +1017,9 @@ def bringup(self, structure, outdir, **kwargs):
10171017
# creates POTCAR file
10181018
logger.debug("vasp/functional bringup: files.POTCAR: %s " % files.POTCAR)
10191019
with open(files.POTCAR, 'w') as potcar:
1020-
self.write_potcar(potcar, structure)
1021-
1020+
for s in specieset(structure):
1021+
outLines = self.species[s].read_potcar()
1022+
potcar.writelines(outLines)
10221023
# Add is running file marker.
10231024
local_path(outdir).join('.pylada_is_running').ensure(file=True)
10241025
self._copy_additional_files(outdir)
@@ -1114,14 +1115,7 @@ def write_kpoints(self, file, structure, kpoints=None):
11141115
outLine = "{0[0]} {0[1]} {0[2]} {1}\n".format(
11151116
kpoint, 1 if len(kpoint) == 3 else kpoint[3])
11161117
file.write(outLine)
1117-
1118-
def write_potcar(self, file, structure):
1119-
""" Writes the potcar file """
1120-
from ..crystal import specieset
1121-
for s in specieset(structure):
1122-
outLines = self.species[s].read_potcar()
1123-
file.writelines(outLines)
1124-
1118+
11251119
def __repr__(self, defaults=True, name=None):
11261120
""" Returns representation of this instance """
11271121
from ..tools.uirepr import uirepr

src/pylada/vasp/keywords.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,10 @@ def value(self, value):
356356
if value is None:
357357
self._value = None
358358
return None
359-
from pylada import is_vasp_4
359+
try:
360+
from pylada import is_vasp_4
361+
except:
362+
is_vasp_4 = False
360363
if not hasattr(value, 'lower'):
361364
raise TypeError("ALGO cannot be set with {0}.".format(value))
362365
lower = value.lower().rstrip().lstrip()
@@ -871,8 +874,7 @@ def output_map(self, **kwargs):
871874
from ..error import ValueError
872875
from ..crystal import write, read, specieset
873876
from . import files
874-
from pylada import is_vasp_4
875-
877+
876878
istruc = self._value
877879
if istruc is None:
878880
istruc = 0
@@ -886,7 +888,7 @@ def output_map(self, **kwargs):
886888
has_restart = vasp.restart.success
887889
if has_restart:
888890
structure = vasp.restart.structure
889-
891+
890892
# determines which CONTCAR is the latest, if any exist.
891893
if istruc in [-1, 1]:
892894
last_contcar = latest_file(join(outdir, files.CONTCAR))
@@ -896,6 +898,7 @@ def output_map(self, **kwargs):
896898
# specifically, the order of the atoms of a given specie are the same).
897899
if last_contcar is not None:
898900
other = read.poscar(path=last_contcar, types=specieset(structure))
901+
899902
if len(other) != len(structure):
900903
raise ValueError('CONTCAR and input structure differ in size.')
901904
for type in specieset(other):
@@ -908,6 +911,9 @@ def output_map(self, **kwargs):
908911
if a.type != type:
909912
continue
910913
a.pos = b.pos
914+
if len(getattr(b, 'freeze', '')) != 0:
915+
a.freeze = b.freeze
916+
911917
structure.cell = other.cell
912918
structure.scale = other.scale
913919
print("setting cell and scale!")
@@ -920,7 +926,8 @@ def output_map(self, **kwargs):
920926
raise ValueError('Structure scale is zero')
921927
if structure.volume < 1e-8:
922928
raise ValueError('Structure volume is zero')
923-
write.poscar(structure, join(outdir, 'POSCAR'), vasp5=not is_vasp_4)
929+
930+
write.poscar(structure, join(outdir, 'POSCAR'))
924931
return None
925932

926933

0 commit comments

Comments
 (0)