Skip to content

Commit

Permalink
Merge pull request #67 from pylada/pwscf_fixes
Browse files Browse the repository at this point in the history
fixing some bugs
  • Loading branch information
mdavezac authored Aug 18, 2023
2 parents f86917d + cd8509f commit 1516ea5
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 14 deletions.
1 change: 1 addition & 0 deletions pylada
3 changes: 2 additions & 1 deletion src/pylada/crystal/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ def icsd_cif_a(filename, make_primitive=True):
from numpy import array, transpose
from numpy import pi, sin, cos, sqrt, dot

lines = open(filename, 'r').readlines()
#vladan lines = open(filename, 'r').readlines()
lines = open(filename, 'r',encoding= 'unicode_escape').readlines()
logger.info("crystal/read: icsd_cif_a: %s" % filename)

sym_big = 0
Expand Down
2 changes: 2 additions & 0 deletions src/pylada/espresso/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def __cell(self, structure):
cards = [u for u in read_cards(self.output_path.open(mode='r'))
if u.name == 'cell_parameters']
structure.cell = [u.split() for u in cards[-1].value.split('\n')]
# vladan: transposing so the cell vectors are rows and not columns
structure.cell = structure.cell.T

@property
@make_cached
Expand Down
9 changes: 6 additions & 3 deletions src/pylada/espresso/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ def iter(self, structure, outdir=".", comm=None, overwrite=False, restart=None,
if not overwrite:
# Check with this instance's Extract, cos it is this calculation we shall
# do here. Derived instance's Extract might be checking for other stuff.
extract = self.Extract(str(outdir))
#vladan extract = self.Extract(str(outdir))
extract = self.Extract(str(outdir),prefix=self.control.prefix)
if extract.success:
yield extract # in which case, returns extraction object.
return
Expand Down Expand Up @@ -296,7 +297,8 @@ def onfinish(process, error):
stdin=stdin, stdout=stdout, stderr=stderr,
dompi=comm is not None)
# yields final extraction object.
yield self.Extract(str(outdir))
#vladan yield self.Extract(str(outdir))
yield self.Extract(str(outdir),prefix=self.control.prefix)

def pseudos_do_exist(self, structure, verbose=False):
""" True if it all pseudos exist
Expand Down Expand Up @@ -329,7 +331,8 @@ def _restarting(self, structure, restart, outdir):
return structure

# normalize: restart could be an Extract object, or a path
restart = self.Extract(restart)
#vladan restart = self.Extract(restart)
restart = self.Extract(str(outdir),prefix=self.control.prefix)
if not restart.success:
logger.critical("Cannot restart from unsuccessful calculation")
raise error.RuntimeError("Cannot restart from unsuccessful calculation")
Expand Down
14 changes: 12 additions & 2 deletions src/pylada/espresso/pwscf_namelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,17 @@ class Cell(Namelist):
cell_factor = Float(allow_none=True, default_value=None, min=0e0,
help="Used when constructing pseudopotential tables")
factor = alias(cell_factor)
cell_dofree = CaselessStringEnum(['all', 'x', 'y', 'z', 'xy', 'xz', 'yz', 'shape', 'volume',
'2Dxy', '2Dshape'], default_value=None, allow_none=True,

#vladan
#cell_dofree = CaselessStringEnum(['all', 'x', 'y', 'z', 'xy', 'xz', 'yz', 'shape', 'volume',
# '2Dxy', '2Dshape'], default_value=None, allow_none=True,
# help="Degrees of freedom during relaxation")

cell_dofree = CaselessStringEnum(['all', 'a', 'b', 'c', 'fixa', 'fixb', 'fixc',
'x', 'y', 'z', 'xy', 'xz', 'yz', 'shape', 'volume',
'2Dxy', '2Dshape', 'epitaxial_ab', 'epitaxial_ac', 'epitaxial_bc'],
default_value=None, allow_none=True,
help="Degrees of freedom during relaxation")


dofree = alias(cell_dofree)
22 changes: 19 additions & 3 deletions src/pylada/espresso/structure_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,26 @@ def add_structure(structure, f90namelist, cards):
positions = card_dict['atomic_positions']
positions.subtitle = 'alat'
positions.value = ""
for atom in structure:
positions.value += "%s %18.12e %18.12e %18.12e\n" % (atom.type, atom.pos[0], atom.pos[1],
atom.pos[2])

#vladan
#for atom in structure:
# positions.value += "%s %18.12e %18.12e %18.12e\n" % (atom.type, atom.pos[0], atom.pos[1], atom.pos[2])

# new code for selective dynamics (by Matt Jank.)
selective_dynamics = any([len(getattr(atom, 'freeze', '')) != 0 for atom in structure])

for atom in structure:
if not selective_dynamics:
positions.value += "%s %18.12e %18.12e %18.12e\n" % (atom.type, atom.pos[0],
atom.pos[1], atom.pos[2])
else:
positions.value += "%s %18.12e %18.12e %18.12e %i %i %i\n"
%(atom.type, atom.pos[0],atom.pos[1], atom.pos[2],
'x' not in getattr(atom, 'freeze', ''),
'y' not in getattr(atom, 'freeze', ''),
'z' not in getattr(atom, 'freeze', ''))
# end selective dynamics modification

__add_forces_to_input(cards, structure)


Expand Down
3 changes: 2 additions & 1 deletion src/pylada/ipython/launch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def mppalloc(job):
""" Returns number of processes for this job. """
natom = len(job.structure) # number of atoms.
# Round down to a multiple of ppn
nnode = max(1, natom / event.ppn)
#vladan nnode = max(1, natom / event.ppn)
nnode = max(1, natom // event.ppn)
nproc = nnode * event.ppn
return nproc
logger.info("launch/init: mppalloc b: %s" % mppalloc)
Expand Down
14 changes: 12 additions & 2 deletions src/pylada/ipython/launch/scattered.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,23 @@ def pbspaths(directory, jobname, suffix):
# added by Peter Graf
# avoid jobfolder which is already in the queue:
qstuff = qstat(name)
# vladan
# qstat(name) will return all jobs with names whose first parts
# match the name. For example qstat('job.12') will return the
# both 'job.12' and 'job.123'. So, Peter's stuff has a bug, if
# 'job.123' is in the queue pylada will think 'job.12' is also.
# To deal with this one can do:
qstuff = [x for x in qstuff if x.split()[-1]==name]
if (len(qstuff) > 0 and not event.force):
status = [x.split()[2] for x in qstuff]
#status = [x.split()[2] for x in qstuff]
status = qstuff[0].split()[2]
# status is a list like ['Q'], ['R'], ['H'], ['C'], ['R', 'C'], etc
# 'RHQ' is the status that the job is indeed in the queue, 'C' job completed and
# being removed from the queue if needed, a prefix can be used to distinguish two
# jobs with the same name
if len(set(status) & set('RHQ')) > 0:
queue_options=['R','H','Q','PD','C'] # I (vladan) find this to work better
#if len(set(status) & set('RHQ')) > 0: # this was before, also has problems
if (status in queue_options):
print(("Job %s is in the queue, will not be re-queued" % name))
continue

Expand Down
3 changes: 2 additions & 1 deletion src/pylada/ipython/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def qdel(self, arg):
message = "Are you sure you want to cancel"\
"the jobs listed above? [y/n] "
else:
message = "Cancel all jobs? [y/n] "
#vladan message = "Cancel all jobs? [y/n] "
message = "Cancel all %s jobs? [y/n] " %(arg)
key = ''
while key not in ['n', 'y']:
key = cmdl_input(message)
Expand Down
3 changes: 2 additions & 1 deletion src/pylada/misc/relativepath.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ def hook(self):
@hook.setter
def hook(self, value):
from sys import version_info
from inspect import ismethod, getargspec, isfunction
#vladan from inspect import ismethod, getargspec, isfunction
from inspect import ismethod, isfunction
if version_info[0] == 2:
from inspect import getargspec
else:
Expand Down

0 comments on commit 1516ea5

Please sign in to comment.