Skip to content

Bugfix: update pypif behavior #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dfttopif/parsers/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
from collections import Counter
from pypif.obj.common import Value, Property
from pypif.obj.common import Value, Property, Scalar


def Value_if_true(func):
'''Returns:
Value if x is True, else None'''
return lambda x: Value() if func(x) == True else None
return lambda x: Value(scalars=[Scalar(value=True)]) if func(x) == True else Value(scalars=[Scalar(value=False)])


class DFTParser(object):
Expand Down Expand Up @@ -212,7 +212,7 @@ def is_converged(self):
# Check for cached result
if self._converged is None:
self._converged = self._is_converged()
return Property(scalars=self._converged)
return Property(scalars=[Scalar(value=self._converged)])

def get_pp_name(self):
'''Read output to get the pseudopotentials names used for each elements
Expand Down
27 changes: 14 additions & 13 deletions dfttopif/parsers/pwscf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pypif.obj.common.property import Property
from pypif.obj.common import Property, Scalar

from .base import DFTParser, Value_if_true
import os
Expand Down Expand Up @@ -69,12 +69,12 @@ def get_xc_functional(self):
if xcstring[word][0] == '(':
xcstring = xcstring[:word]
break
return Value(scalars=" ".join(xcstring))
return Value(scalars=[Scalar(value=" ".join(xcstring))])

def get_cutoff_energy(self):
'''Determine the cutoff energy from the output'''
cutoff = self._get_line('kinetic-energy cutoff', self.outputf).split()[3:]
return Value(scalars=float(cutoff[0]), units=cutoff[1])
return Value(scalars=[Scalar(value=float(cutoff[0]))], units=cutoff[1])

def get_total_energy(self):
'''Determine the total energy from the output'''
Expand All @@ -83,23 +83,24 @@ def get_total_energy(self):
for line in reversed(fp.readlines()):
if "!" in line and "total energy" in line:
energy = line.split()[4:]
return Property(scalars=float(energy[0]), units=energy[1])
return Property(scalars=[Scalar(value=float(energy[0]))], units=energy[1])
raise Exception('%s not found in %s'%('! & total energy',os.path.join(self._directory, self.outputf)))

@Value_if_true
def is_relaxed(self):
'''Determine if relaxation run from the output'''
return self._get_line('Geometry Optimization', self.outputf, return_string=False)
result = self._get_line('Geometry Optimization', self.outputf, return_string=False)
return Property(scalars=[Scalar(value=result)])

def _is_converged(self):
'''Determine if calculation converged; for a relaxation (static) run
we look for ionic (electronic) convergence in the output'''
if self.is_relaxed():
if self.is_relaxed().scalars[0].value:
# relaxation run case
return self._get_line(['End of', 'Geometry Optimization'], self.outputf, return_string=False)
result = self._get_line(['End of', 'Geometry Optimization'], self.outputf, return_string=False)
else:
# static run case
return self._get_line('convergence has been achieved', self.outputf, return_string=False)
result = self._get_line('convergence has been achieved', self.outputf, return_string=False)
return result

def get_KPPRA(self):
'''Determine the no. of k-points in the BZ (from the input) times the
Expand Down Expand Up @@ -143,10 +144,10 @@ def get_KPPRA(self):
fp.close()
raise Exception('%s not found in %s'%('KPOINTS',os.path.join(self._directory, self.inputf)))

@Value_if_true
def uses_SOC(self):
'''Looks for line with "with spin-orbit" in the output'''
return self._get_line('with spin-orbit', self.outputf, return_string=False)
result = self._get_line('with spin-orbit', self.outputf, return_string=False)
return Property(scalars=[Scalar(value=result)])

def get_pp_name(self):
'''Determine the pseudopotential names from the output'''
Expand Down Expand Up @@ -262,7 +263,7 @@ def get_output_structure(self):
break
if len(coords) == 0: raise Exception('Cannot find the initial atomic coordinates')

if type(self.is_relaxed()) == type(None):
if not self.is_relaxed().scalars[0].value:
# static run: create, populate, and return the initial structure
structure = Atoms(symbols=atom_symbols, cell=unit_cell, pbc=True)
structure.set_positions(coords)
Expand Down Expand Up @@ -339,7 +340,7 @@ def get_dos(self):
ls = line.split()
energy.append(float(ls[0])-efermi)
dos.append(sum([float(i) for i in ls[1:1+ndoscol]]))
return Property(scalars=dos, units='number of states per unit cell', conditions=Value(name='energy', scalars=energy, units='eV'))
return Property(scalars=[Scalar(value=x) for x in dos], units='number of states per unit cell', conditions=Value(name='energy', scalars=[Scalar(value=x) for x in energy], units='eV'))

def get_forces(self):
return None
Expand Down
6 changes: 3 additions & 3 deletions dfttopif/parsers/vasp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pypif.obj.common.property import Property
from pypif.obj.common import Property, Scalar

from .base import DFTParser, Value_if_true
import os
Expand Down Expand Up @@ -53,7 +53,7 @@ def get_cutoff_energy(self):
for line in fp:
if "ENCUT" in line:
words = line.split()
return Value(scalars=float(words[2]), units=words[3])
return Value(scalars=[Scalar(value=float(words[2]))], units=words[3])

# Error handling: ENCUT not found
raise Exception('ENCUT not found')
Expand Down Expand Up @@ -149,7 +149,7 @@ def _is_converged(self):
return self._call_ase(Vasp().read_convergence)

def get_total_energy(self):
return Property(scalars=self._call_ase(Vasp().read_energy)[0], units='eV')
return Property(scalars=[Scalar(value=self._call_ase(Vasp().read_energy)[0])], units='eV')

def get_version_number(self):
# Open up the OUTCAR
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ requests
flask
flask-cors
gunicorn
pypif==1.1.6
pypif==1.2.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
url='https://github.com/CitrineInformatics/pif-dft',
install_requires=[
'ase',
'pypif==1.1.6',
'pypif>=1.2.0,<1.3.0',
],
extras_require={
'report': ["requests"],
Expand Down
4 changes: 2 additions & 2 deletions tests/parsers/test_pwscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_NaF(self):
self.assertEquals(-143.96084355, energy.scalars[0].value)
self.assertEquals('Ry', energy.units)

self.assertEquals(None, parser.uses_SOC())
self.assertEquals(None, parser.is_relaxed())
self.assertEquals(False, parser.uses_SOC().scalars[0].value)
self.assertEquals(False, parser.is_relaxed().scalars[0].value)
self.assertEquals('SLA PW PBE PBE', parser.get_xc_functional().scalars[0].value)
self.assertEquals(['f_pbe_v1.4.uspp.F.UPF','Na_pbe_v1.uspp.F.UPF'], list(map(lambda x: x.value, parser.get_pp_name().scalars)))
self.assertEquals(3456, parser.get_KPPRA().scalars[0].value)
Expand Down