From 9e386d1f6bff998ea937fe2d32d139b07f38de4b Mon Sep 17 00:00:00 2001 From: Max Hutchinson Date: Fri, 5 May 2017 13:55:29 -0500 Subject: [PATCH 1/3] Fixing some tests --- dfttopif/parsers/base.py | 6 +++--- dfttopif/parsers/pwscf.py | 6 +++--- dfttopif/parsers/vasp.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dfttopif/parsers/base.py b/dfttopif/parsers/base.py index 25dd4a2..97b2be3 100644 --- a/dfttopif/parsers/base.py +++ b/dfttopif/parsers/base.py @@ -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): @@ -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 diff --git a/dfttopif/parsers/pwscf.py b/dfttopif/parsers/pwscf.py index da7d6e0..785c4f0 100644 --- a/dfttopif/parsers/pwscf.py +++ b/dfttopif/parsers/pwscf.py @@ -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 @@ -74,7 +74,7 @@ def get_xc_functional(self): 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''' @@ -83,7 +83,7 @@ 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 diff --git a/dfttopif/parsers/vasp.py b/dfttopif/parsers/vasp.py index 77d14dc..2f3738e 100644 --- a/dfttopif/parsers/vasp.py +++ b/dfttopif/parsers/vasp.py @@ -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 @@ -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') @@ -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 From 327fb053137c2c57a9ec854f84ee2d9b3d25678f Mon Sep 17 00:00:00 2001 From: Max Hutchinson Date: Mon, 8 May 2017 16:13:09 -0500 Subject: [PATCH 2/3] Updating pypif version. --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index af47b73..80659c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ requests flask flask-cors gunicorn -pypif==1.1.6 +pypif==1.2.0 diff --git a/setup.py b/setup.py index 5b99daf..00d545c 100644 --- a/setup.py +++ b/setup.py @@ -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"], From c60dab8b0918412ea903c310058fd0bbbe599bfb Mon Sep 17 00:00:00 2001 From: Max Hutchinson Date: Tue, 9 May 2017 07:31:03 -0500 Subject: [PATCH 3/3] Making more progress --- dfttopif/parsers/pwscf.py | 21 +++++++++++---------- tests/parsers/test_pwscf.py | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/dfttopif/parsers/pwscf.py b/dfttopif/parsers/pwscf.py index 785c4f0..4befe3a 100644 --- a/dfttopif/parsers/pwscf.py +++ b/dfttopif/parsers/pwscf.py @@ -69,7 +69,7 @@ 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''' @@ -86,20 +86,21 @@ def get_total_energy(self): 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 @@ -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''' @@ -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) @@ -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 diff --git a/tests/parsers/test_pwscf.py b/tests/parsers/test_pwscf.py index 47b6ee2..52bdaed 100644 --- a/tests/parsers/test_pwscf.py +++ b/tests/parsers/test_pwscf.py @@ -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)