예제 #1
0
파일: vasp.py 프로젝트: nitin0301/pif-dft
 def get_KPPRA(self):
     # Open up the OUTCAR
     with open(self.outcar) as fp:
         #store the number of atoms and number of irreducible K-points
         for line in fp:
             if "number of ions     NIONS =" in line:
                 words = line.split()
                 NI = int(words[11])
             elif "k-points           NKPTS =" in line:
                 words = line.split()
                 NIRK = float(words[3])
         #check if the number of k-points was reduced by VASP if so, sum all the k-points weight
         if "irreducible" in open(self.outcar).read():
             fp.seek(0)
             for line in fp:
                 #sum all the k-points weight
                 if "Coordinates               Weight" in line:
                     NK = 0
                     counter = 0
                     for line in fp:
                         if counter == NIRK:
                             break
                         NK += float(line.split()[3])
                         counter += 1
             return Value(scalars=[Scalar(value=NI * NK)])
         #if k-points were not reduced KPPRA equals the number of atoms * number of irreducible k-points
         else:
             return Value(scalars=[Scalar(value=NI * NIRK)])
예제 #2
0
    def get_KPPRA(self):
        # Open up the OUTCAR
        with open(os.path.join(self._directory, 'OUTCAR')) as fp:
            #store the number of atoms and number of irreducible K-points
            for line in fp:
                if "NIONS" in line:
                    words = line.split()
                    NI = int(words[11])
                elif "NKPTS" in line:
                    words = line.split()
                    NIRK = float(words[3])
            #check if the number of k-points was reduced by VASP if so, sum all the k-points weight
            if "irreducible" in open(os.path.join(self._directory,
                                                  'OUTCAR')).read():
                fp.seek(0)
                for line in fp:
                    #sum all the k-points weight
                    if "Coordinates               Weight" in line:
                        NK = 0
                        counter = 0
                        for line in fp:
                            if counter == NIRK:
                                break
                            NK += float(line.split()[3])
                            counter += 1
                return Value(scalars=[Scalar(value=NI * NK)])
            #if k-points were not reduced KPPRA equals the number of atoms * number of irreducible k-points
            else:
                return Value(scalars=[Scalar(value=NI * NIRK)])

        # Error handling: NKPTS or NIONS not found
        raise Exception('NIONS, irredicuble or Coordinates not found')
예제 #3
0
    def get_dos(self):
        file_path = os.path.join(self._directory, 'DOSCAR')
        if not os.path.isfile(file_path):
            return None
        #open DOSCAR
        with open(os.path.join(self._directory, 'DOSCAR')) as fp:
            for i in range(6):
                l = fp.readline()
            n_step = int(l.split()[2])
            energy = []
            dos = []
            for i in range(n_step):
                l = fp.readline().split()
                e = float(l.pop(0))
                energy.append(Scalar(value=e))
                dens = 0
                for j in range(int(len(l) / 2)):
                    dens += float(l[j])
                dos.append(Scalar(value=dens))

            # Convert to property
            return Property(scalars=dos,
                            units='number of states per unit cell',
                            conditions=Value(name='energy',
                                             scalars=energy,
                                             units='eV'))
예제 #4
0
파일: vasp.py 프로젝트: nitin0301/pif-dft
    def get_xc_functional(self):
        # Open up the OUTCAR
        with open(self.outcar) as fp:

            # Look for TITEL
            for line in fp:
                if "TITEL" in line:
                    words = line.split()
                    return Value(scalars=[Scalar(value=words[2])])
예제 #5
0
    def get_xc_functional(self):
        # Open up the OUTCAR
        with open(os.path.join(self._directory, 'OUTCAR')) as fp:

            # Look for TITEL
            for line in fp:
                if "TITEL" in line:
                    words = line.split()
                    return Value(scalars=[Scalar(value=words[2])])
                    break
예제 #6
0
 def get_forces(self):
     self.atoms = read_vasp_out(os.path.join(self._directory, 'OUTCAR'))
     forces_raw = self.atoms.get_calculator().results['forces'].tolist()
     forces_wrapped = [[Scalar(value=x) for x in y] for y in forces_raw]
     positions_raw = self.atoms.positions.tolist()
     positions_wrapped = [[Scalar(value=x) for x in y]
                          for y in positions_raw]
     return Property(vectors=forces_wrapped,
                     conditions=Value(name="positions",
                                      vectors=positions_wrapped))
예제 #7
0
def test_condition_elevation():
    """Test that read views elevate conditions"""
    condition = Value(name="spam", scalars=[Scalar(value="eggs")])
    pif = System(properties=[
        Property(
            name="foo", scalars=[Scalar(value="bar")], conditions=[condition])
    ])
    r = ReadView(pif)
    assert r["foo"].scalars[0].value == "bar", "Didn't elevate property key"
    assert r["spam"].scalars[0].value == "eggs", "Didn't elevate condition key"
예제 #8
0
    def get_cutoff_energy(self):
        # Open up the OUTCAR
        with open(os.path.join(self._directory, 'OUTCAR'), 'r') as fp:
            # Look for ENCUT
            for line in fp:
                if "ENCUT" in line:
                    words = line.split()
                    return Value(scalars=[Scalar(value=float(words[2]))],
                                 units=words[3])

        # Error handling: ENCUT not found
        raise Exception('ENCUT not found')
예제 #9
0
파일: vasp.py 프로젝트: nitin0301/pif-dft
    def get_pp_name(self):
        # Open up the OUTCAR
        with open(self.outcar) as fp:

            #initialize empty list to store pseudopotentials
            pp = []
            # Look for TITEL
            for line in fp:
                if "TITEL" in line:
                    words = line.split()
                    pp.append(words[3])
            return Value(vectors=[[Scalar(value=x) for x in pp]])
예제 #10
0
    def get_pp_name(self):
        # Open up the OUTCAR
        with open(os.path.join(self._directory, 'OUTCAR')) as fp:

            #initialize empty list to store pseudopotentials
            pp = []
            # Look for TITEL
            for line in fp:
                if "TITEL" in line:
                    words = line.split()
                    pp.append(words[3])
            return Value(vectors=[[Scalar(value=x) for x in pp]])

        # Error handling: TITEL not found
        raise Exception('TITEL not found')
예제 #11
0
 def get_U_settings(self):
     #Open up the OUTCAR
     with open(os.path.join(self._directory, 'OUTCAR')) as fp:
         #Check if U is used
         if "LDAU" in open(os.path.join(self._directory, 'OUTCAR')).read():
             U_param = {}
             atoms = []
             #get the list of pseupotential used
             for line in fp:
                 if "TITEL" in line:
                     atoms.append(line.split()[3])
                 #Get the U type used
                 if "LDAUTYPE" in line:
                     U_param['Type'] = int(line.split()[-1])
             atoms.reverse()
             fp.seek(0)
             #Get the L value
             U_param['Values'] = {}
             for line in fp:
                 for atom, i in zip(atoms, range(len(atoms))):
                     if "LDAUL" in line:
                         U_param['Values'][atom] = {
                             'L': int(line.split()[-1 - i])
                         }
             fp.seek(0)
             #Get the U value
             for line in fp:
                 for atom, i in zip(atoms, range(len(atoms))):
                     if "LDAUU" in line:
                         U_param['Values'][atom]['U'] = float(
                             line.split()[-1 - i])
             fp.seek(0)
             #Get the J value
             for line in fp:
                 for atom, i in zip(atoms, range(len(atoms))):
                     if "LDAUJ" in line:
                         U_param['Values'][atom]['J'] = float(
                             line.split()[-1 - i])
             return Value(**U_param)
         #if U is not used, return None
         else:
             return None
예제 #12
0
파일: vasp.py 프로젝트: nitin0301/pif-dft
 def get_vdW_settings(self):
     #define the name of the vdW methods in function of their keyword
     vdW_dict = {
         'BO': 'optPBE-vdW',
         'MK': 'optB88-vdW',
         'ML': 'optB86b-vdW',
         'RE': 'vdW-DF',
         'OR': 'Klimes-Bowler-Michaelides'
     }
     #Open up the OUTCAR
     with open(self.outcar) as fp:
         #Check if vdW is used
         if "LUSE_VDW" in open(self.outcar).read():
             #if vdW is used, get its keyword
             for line in fp:
                 if "GGA     =" in line:
                     words = line.split()
                     return Value(
                         scalars=[Scalar(value=vdW_dict[words[2]])])
         #if vdW is not used, return None
         else:
             return None
예제 #13
0
from pypif_sdk.func import replace_by_key, copy
from pypif_sdk.accessor import get_property_by_name
from pypif.obj import System, Property, Scalar, Value, FileReference

test_pif = System(names=["methane"],
                  properties=[
                      Property(name="foo", scalars=[Scalar(value="bar")]),
                      Property(name="spam",
                               units="eV",
                               scalars=[Scalar(value=2.7)],
                               conditions=[
                                   Value(name="tomato",
                                         units="eV",
                                         scalars=[Scalar(value=1.0)])
                               ]),
                      Property(
                          name="image",
                          files=[FileReference(relative_path="/tmp/file.png")])
                  ])


def test_simple_replace():
    """Test replace a single field with default arguments"""
    prop = get_property_by_name(copy(test_pif), "image")
    assert prop.files[
        0].relative_path == "/tmp/file.png", "Didn't shorten file name"
    new_pif = replace_by_key(test_pif, "relative_path",
                             {"/tmp/file.png": "file.png"})
    prop = get_property_by_name(new_pif, "image")
    assert prop.files[
        0].relative_path == "file.png", "Didn't shorten file name"
예제 #14
0
 def get_poscar(self):
     raw_path = os.path.join(self._directory, 'POSCAR')
     if raw_path[0:2] == "./":
         raw_path = raw_path[2:]
     return Value(files=[FileReference(relative_path=raw_path)])
예제 #15
0
파일: vasp.py 프로젝트: nitin0301/pif-dft
 def get_poscar(self):
     if self.poscar is None: return None
     raw_path = self.poscar
     if raw_path[0:2] == "./":
         raw_path = raw_path[2:]
     return Value(files=[FileReference(relative_path=raw_path)])