Esempio n. 1
0
 def __init__(self,POSCAR="POSCAR",resolution=0.001):
     self.multipliers = np.arange(1.0,89,resolution)
     loader = POSCARloader(POSCAR)
     loader.parse()
     self.directions = loader()['directions']
     self.found      = []
     self.volume = np.linalg.det(self.directions)
     self.invert_directions()
Esempio n. 2
0
 def __init__(self, POSCAR):
     loader = POSCARloader(POSCAR)
     loader.parse()
     firstLine = loader()['comment']
     try:
         self.reference = int(
             re.search('NewRef:\s*([0-9]+),', firstLine).group(1))
     except AttributeError as err:
         print("Reference not found in POSCAR comment! Taking 0!")
         print(err)
         self.reference = 0
     except ValueError as err:
         print("Reference cannot be converted to int! Taking 0!")
         print(err)
         self.reference = 0
     if self.reference < 0:
         print("Wrong reference (%d < 0)! Taking 0!" % self.reference)
         self.reference = 0
Esempio n. 3
0
    def load_vasp(poscarfile, incarfile):
        if not exists(poscarfile):
            print('POSCAR file %s does not exist!' % poscarfile)
            exit(Errors.erroneous_input)
        if incarfile is not None and not exists(incarfile):
            print('INCAR file %s does not exist!' % incarfile)
            exit(Errors.erroneous_input)

        load_POSCAR = POSCARloader(poscarfile)
        load_POSCAR.parse()
        readData = load_POSCAR(0)

        if incarfile is None:
            oldMoments = [1.0] * len(readData['cell'])
            return readData, oldMoments, ''

        load_INCAR = loadsave.INCARloader(readData['cell'],
                                          fileName=incarfile,
                                          atomNames=readData['atomNames'])
        oldMoments, incarData = load_INCAR()
        return readData, oldMoments, incarData
Esempio n. 4
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import time
from JorGpi.geometry.voronoi import Voronoi
from JorGpi.POSCARloader import POSCARloader

def main():
    pass

if __name__ == '__main__':
    tracker  = -(time.time())

    loader   = POSCARloader('POSCARsmall','POSCAR','POSCARweird')
    loader.parse()
    for i in range(len(loader)):
        voronoi = Voronoi(data=loader(i))
        voronoi.get_voronoi_diagram(save=True,name="WSradia%03d.dat"%i)
        voronoi.show("output%03d.png"%i)
        voronoi.show()
    tracker += time.time()
    print("Runntime of %02d:%02d:%02d.%09d"%(int(tracker/3600),int(tracker/60),int(tracker),int(1e9*tracker)))
Esempio n. 5
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

from JorGpi.geometry.voronoi import Voronoi
from JorGpi.POSCARloader import POSCARloader
from JorGpi.aux.PeriodicTable import standardMass
import numpy as np

def main():
    pass

if __name__ == '__main__':
    loader   = POSCARloader(*argv[1:])
    loader.parse()
    volume = np.linalg.det(loader()['directions'])
    atoms  = [ atom[0] for atom in loader()['cell']]
    masses = [ standardMass[atom] for atom in atoms ]
    mass   = np.sum(masses)
    RHO    = mass/volume
    for atom,m in zip(loader()['cell'],masses):
        print(atom[0], "@", *atom[1], m, np.cbrt(3*m*volume/(mass*4*np.pi)))
    print(atoms,volume,mass,RHO)
    for i in range(len(loader)):
        voronoi = Voronoi(data=loader(i))
        voronoi.get_voronoi_diagram(save=True,name="%s_WS.txt"%argv[1+i])
        voronoi.show("%s.png"%argv[1+i])
        voronoi.show()
Esempio n. 6
0
 def read_poscars(self, *args):
     lastBackSlashRemoved = [re.sub('/$', '', arg) for arg in args]
     poscars = ["%s/POSCAR" % arg for arg in lastBackSlashRemoved]
     self.poscars = POSCARloader(*poscars)
     self.poscars.parse()
Esempio n. 7
0
class SmartPickUp:
    def __init__(self, numberOfNeighbors, namesOfInteractingAtoms):
        self.numberOfNeighbors = numberOfNeighbors
        self.namesOfInteractingAtoms = namesOfInteractingAtoms
        self.types = EnergyConverter.types

    def read_poscars(self, *args):
        lastBackSlashRemoved = [re.sub('/$', '', arg) for arg in args]
        poscars = ["%s/POSCAR" % arg for arg in lastBackSlashRemoved]
        self.poscars = POSCARloader(*poscars)
        self.poscars.parse()

    def read_magmoms(self, *args):
        vaspruns = ["%s/vasprun.xml" % arg for arg in args]
        self.magmoms = MAGMOMloaderXML(*vaspruns, trapez=True)
        self.magmoms.parse()

    def read(self, *args, **kwargs):
        self.read_magmoms(*args)
        self.read_poscars(*args)
        if 'reference' in kwargs:
            self.reference = self.poscars(0)['cell'][kwargs['reference']][1]
            self.ref = kwargs['reference']
        else:
            print("Warning: reference @ 0. Is that ok?")
            self.ref = 0
            self.reference = self.poscars(0)['cell'][0][1]

    def make_crystal(self, idx=0):
        self.crystal = self.poscars(idx)['cell']
        try:
            self.crystal  = [[atom[0],atom[1],
                             self.magmoms.get_moments()[i+1]]\
                           for i,atom in enumerate(self.crystal) ]
        except KeyError as err:
            print(self.magmoms.get_moments())
            print(err)
            exit(-1)
        self.crystal8 = apply_mirrors_xyz(
            self.poscars(0)['directions'], self.crystal)

    def map_distances(self, idx=0):
        self.distances = set([])
        self.make_crystal(idx)
        for atom in self.poscars(idx)['cell']:
            distance = np.around(np.linalg.norm(atom[1] - self.reference),
                                 decimals=2)
            if atom[0] in self.namesOfInteractingAtoms:
                self.distances.add(distance)
        self.distances = np.sort(np.array(list(
            self.distances)))[1:1 + self.numberOfNeighbors]

    # for sorted!
    def get_system_of_equations(self):
        self.map_distances()
        self.systemOfEquations = []
        deltaEnergy = []
        self.flippingConfigurations = []
        for i in range(1, len(self.magmoms)):
            try:
                deltaEnergy.append(
                    self.magmoms(i)['energy'] - self.magmoms(0)['energy'])
            except TypeError:
                print("VASP hasn't finished this run (%d/%d)" %
                      (i, len(self.magmoms) - 1))
                continue
            self.set_flipps(i)
        self.model = NaiveHeisenberg(self.flippingConfigurations, self.crystal,
                                     self.crystal8)
        self.flipped = np.unique(np.where(self.flippingConfigurations)[1])
        self.systemOfEquations = self.model.generate(
            self.namesOfInteractingAtoms, self.distances, self.magmoms)
        self.solver = EquationSolver(self.systemOfEquations, deltaEnergy)
        self.solver.remove_tautologies()

    def set_flipps(self, i):
        self.flippingConfigurations.append([])
        for idx, atom in enumerate(self.poscars(0)['cell']):
            self.get_flip(i, idx, atom)

    def get_flip(self, i, idx, atom):
        if atom[0] not in self.namesOfInteractingAtoms:
            self.flippingConfigurations[-1].append(False)
            return
        momentA = self.magmoms(0)['moments'][idx + 1]
        momentB = self.magmoms(i)['moments'][idx + 1]
        scalar = momentA * momentB
        if (abs(scalar) > 1e-5 and scalar < 0.0):
            self.flippingConfigurations[-1].append(True)
            return
        self.flippingConfigurations[-1].append(False)

    def solve(self, **kwargs):
        try:
            self.solver
        except AttributeError:
            self.get_system_of_equations()

        self._J_ij = np.array(
            EnergyConverter.convert(*(self.solver.solve()),
                                    moments=self.model.get_average_moments(),
                                    **kwargs))
        return self._J_ij

    def __str__(self):
        metaData = self.model.get_metadata()
        try:
            strout = '                       '
            strout += ''.join(["%s | " % name
                               for name in metaData.names]) + '\n'
        except AttributeError:
            return "Error"
        try:
            strout += ''.join([ ("  %s:\t"+len(self._J_ij[0])*"  % 8.3f    "+"\n")\
                                %(typeName,
                                  *self._J_ij[i],)\
                        for i,typeName in enumerate(self.types) ])
            strout += '        <|µ|> (µB):       '
            strout += ''.join(["% 8.3f      " % mu
                               for mu in metaData.moments]) + '\n'
        except AttributeError:
            return strout
        try:
            strout += '            <Δµ/µ>:       '
            strout += ''.join(
                ["% 8.3f      " % corr for corr in metaData.corrections])
        except AttributeError:
            return strout
        return strout
Esempio n. 8
0
 def test_parse_constrains_nodata(self):
     constr = POSCARloader.parse_constrains(self.atom_input_constr)
     self.assertEqual(constr,[True, False, False])
Esempio n. 9
0
class TestPOSCARloader(unittest.TestCase):
    atom_input = "0.0000000000 0.0000000000 4.3870399043 Cu"
    atom_proper = np.array([0.0000000000,0.0000000000,4.3870399043])
    atom_input_constr = "-0.00000000000000 0.00000000000000 0.36270017366243 True False False"
    atom_constr_proper = np.array([-0.00000000000000,0.00000000000000,0.36270017366243])
    directions = [(3.87753641405488, -0.0, -0.0),
                 (-0.0, 3.87753641405488, 0.0),
                 (0.0, 0.0, 12.09549987244948)]
    cell       = [(0.5, 0.5, 0.19398936278918),
                  (0.5, 0.5, 0.80601063721082),
                  (0.0, 0.0, 0.0),
                  (-0.0, 0.0, 0.36270017366243),
                  (0.0, -0.0, 0.63729982633757),
                  (0.0, -0.0, 0.15023942974438),
                  (-0.0, 0.0, 0.84976057025562),
                  (0.0, 0.5, 0.37983766131592),
                  (0.5, 0.0, 0.37983766131592),
                  (-0.0, 0.5, 0.62016233868408),
                  (0.5, -0.0, 0.62016233868408),
                  (0.5, 0.5, 0.5)]
    atoms      = [56, 56, 29, 29, 29, 8, 8, 8, 8, 8, 8, 39]

    def setUp(self):
        self.loader   = POSCARloader('testData/POSCAR_exp1','testData/POSCAR_exp2','testData/POSCAR_exp3')

    def tearDown(self):
        del self.loader

    def test_parse_atom(self):
        atom = POSCARloader.parse_atom(self.atom_input)
        self.assertAlmostEqual(np.linalg.norm(atom-self.atom_proper),0.0)

    def test_parse_atom_constrains(self):
        atom = POSCARloader.parse_atom(self.atom_input_constr)
        self.assertAlmostEqual(np.linalg.norm(atom-self.atom_constr_proper),0.0)

    def test_parse_name(self):
        name = POSCARloader.parse_atom_name(self.atom_input)
        self.assertEqual(name,'Cu')

    def test_parse_name_constrains(self):
        name = POSCARloader.parse_atom_name(self.atom_input_constr)
        self.assertEqual(name,'True')

    def test_parse_constrains(self):
        constr = POSCARloader.parse_constrains(self.atom_input)
        self.assertIsNone(constr)

    def test_parse_constrains_nodata(self):
        constr = POSCARloader.parse_constrains(self.atom_input_constr)
        self.assertEqual(constr,[True, False, False])

    def test_loader_comment(self):
        self.loader.parse()
        self.assertEqual(self.loader(0)['comment'],"Ba2Cu3O6Y1 [TET,TET,tP12] (STD_PRIM do")
        self.assertEqual(self.loader(1)['comment'],"Ba2Cu3O6Y1 [TET,TET,tP12] (STD_PRIM do")
        self.assertEqual(self.loader(2)['comment'],"Ba2Cu3O6Y1 [TET,TET,tP12] (STD_PRIM do")

    def test_loader_directions(self):
        self.loader.parse()
        self.assertAlmostEqual(np.linalg.det(self.loader(0)['directions']),181.8593318589)
        self.assertAlmostEqual(np.linalg.det(self.loader(1)['directions']),181.85933185544175)
        self.assertAlmostEqual(np.linalg.det(self.loader(2)['directions']),181.85933185544175)

    def test_loader_cell_volume(self):
        self.loader.parse()
        self.assertAlmostEqual(self.loader(0)['cellVolume'],181.8593318589)
        self.assertAlmostEqual(self.loader(1)['cellVolume'],181.85933185544175)
        self.assertAlmostEqual(self.loader(2)['cellVolume'],181.85933185544175)

    def test_loader_cell_center(self):
        centerOne = np.array([0.80988675,0.81115342,5.54377077])
        centerTwo = np.array([0.80782009,0.80782009,5.54377077])
        self.loader.parse()
        self.assertAlmostEqual(np.linalg.norm(self.loader(0)['cellCenter']-centerOne),0.0)
        self.assertAlmostEqual(np.linalg.norm(self.loader(1)['cellCenter']-centerTwo),0.0)
        self.assertAlmostEqual(np.linalg.norm(self.loader(2)['cellCenter']-centerTwo),0.0)

    def test_loader_cell_atoms(self):
        cellAtoms = [2,3,6,1]
        self.loader.parse()
        for i,number in enumerate(cellAtoms):
            self.assertEqual(self.loader(0)['cellAtoms'][i],number)
            self.assertEqual(self.loader(1)['cellAtoms'][i],number)
            self.assertEqual(self.loader(2)['cellAtoms'][i],number)

    def test_loader_atom_names(self):
        atomNamesOne = ['Ba', 'Cu', 'O', 'Y']
        atomNamesTwo = ['H', 'He', 'Li', 'Be']
        self.loader.parse()
        for i,name in enumerate(atomNamesOne):
            self.assertEqual(self.loader(0)['atomNames'][i],name)
            self.assertEqual(self.loader(1)['atomNames'][i],name)
        for i,name in enumerate(atomNamesTwo):
            self.assertEqual(self.loader(2)['atomNames'][i],name)

    def are_equal(self,cellA,cellB):
        for atomA,atomB in zip (cellA,cellB):
            self.assertEqual(atomA[0],atomB[0])
            self.assertAlmostEqual(np.linalg.norm(atomA[1]-atomB[1]),0.0,
                                   msg="%s != %s"%(str(atomA[1]),str(atomB[1])))

    def test_loader_cell_0(self):
        self.loader.parse()
        cell = [('Ba', np.array([1.94876821, 1.93876821,  2.34639831])),
                ('Ba', np.array([1.93856821, 1.93876821,  9.74910156])),
                ('Cu', np.array([0.00500000, 0.00000000,  0.00000000])),
                ('Cu', np.array([0.00000000, 0.00000000,  4.3870399 ])),
                ('Cu', np.array([0.00000000, 0.00000000,  7.70845997])),
                ('O' , np.array([0.00600000, 0.00000000,  1.817221  ])),
                ('O' , np.array([0.00000000, 0.00000000, 10.2782788690999993])),
                ('O' , np.array([0.00400000, 1.93876821,  4.59432638])),
                ('O' , np.array([1.93876821, 0.04000000,  4.59432638])),
                ('O' , np.array([0.00000000, 1.93876821,  7.50117349])),
                ('O' , np.array([1.93876821, 0.00000000,  7.50117349])),
                ('Y' , np.array([1.93876821, 1.93876821,  6.04774994]))]
        self.are_equal(cell,self.loader(0)[ 'cell'])

    def test_loader_cell_1(self):
        self.loader.parse()
        cell = [('Ba', np.array([1.93876821, 1.93876821,  2.34639831])),
                ('Ba', np.array([1.93876821, 1.93876821,  9.74910156])),
                ('Cu', np.array([0.00000000, 0.00000000,  0.00000000])),
                ('Cu', np.array([0.00000000, 0.00000000,  4.3870399])),
                ('Cu', np.array([0.00000000, 0.00000000,  7.70845997])),
                ('O' , np.array([0.00000000, 0.00000000,  1.817221])),
                ('O' , np.array([0.00000000, 0.00000000, 10.27827887])),
                ('O' , np.array([0.00000000, 1.93876821,  4.59432638])),
                ('O' , np.array([1.93876821, 0.00000000,  4.59432638])),
                ('O' , np.array([0.00000000, 1.93876821,  7.50117349])),
                ('O' , np.array([1.93876821, 0.00000000,  7.50117349])),
                ('Y' , np.array([1.93876821, 1.93876821,  6.04774994]))]
        self.are_equal(cell,self.loader(1)[ 'cell'])

    def test_loader_cell_2(self):
        self.loader.parse()
        cell = [(0, np.array([1.93876821, 1.93876821,  2.34639831])),
                (0, np.array([1.93876821, 1.93876821,  9.74910156])),
                (1, np.array([0.00000000, 0.00000000,  0.00000000])),
                (1, np.array([0.00000000, 0.00000000,  4.3870399])),
                (1, np.array([0.00000000, 0.00000000,  7.70845997])),
                (2, np.array([0.00000000, 0.00000000,  1.817221])),
                (2, np.array([0.00000000, 0.00000000, 10.27827887])),
                (2, np.array([0.00000000, 1.93876821,  4.59432638])),
                (2, np.array([1.93876821, 0.00000000,  4.59432638])),
                (2, np.array([0.00000000, 1.93876821,  7.50117349])),
                (2, np.array([1.93876821, 0.00000000,  7.50117349])),
                (3, np.array([1.93876821, 1.93876821,  6.04774994]))]
        self.are_equal(cell,self.loader(2)[ 'cell'])

    def test_loader_cell_symmetry_0(self):
        self.loader.parse()
        cell       = [(0.5025789570959635, 0.4999999999871052, 0.19398936279219897),
                      (0.49994842084544383, 0.4999999999871052, 0.8060106372160686),
                      (0.0012894785415343496, 0.0, 0.0),
                      (0.0, 0.0, 0.3627001736662843),
                      (0.0, 0.0, 0.6372998263419832),
                      (0.0015473742498412196, 0.0, 0.1502394297441653),
                      (0.0, 0.0, 0.8497605702558346),
                      (0.0010315828332274797, 0.4999999999871052, 0.3798376613176211),
                      (0.4999999999871052, 0.010315828332274797, 0.3798376613176211),
                      (0.0, 0.4999999999871052, 0.6201623386906465),
                      (0.4999999999871052, 0.0, 0.6201623386906465),
                      (0.4999999999871052, 0.4999999999871052, 0.5)]
        for directionSet,directionRead in zip(self.directions,
                                              self.loader(0)['cellSymmetry'][0]):
            self.assertAlmostEqual(np.linalg.norm(directionSet),
                                   np.linalg.norm(directionRead))
        for atomSet,atomRead in zip(cell,
                                    self.loader(0)['cellSymmetry'][1]):
            self.assertAlmostEqual(np.linalg.norm(atomSet),
                                   np.linalg.norm(atomRead))
        for nameSet,nameRead in zip(self.atoms,
                                    self.loader(0)['cellSymmetry'][2]):
            self.assertEqual(nameSet,nameRead)

    def test_loader_cell_symmetry_1(self):
        self.loader.parse()
        for directionSet,directionRead in zip(self.directions,
                                              self.loader(1)['cellSymmetry'][0]):
            self.assertAlmostEqual(np.linalg.norm(directionSet),
                                   np.linalg.norm(directionRead))
        for atomSet,atomRead in zip(self.cell,
                                    self.loader(1)['cellSymmetry'][1]):
            self.assertAlmostEqual(np.linalg.norm(atomSet),
                                   np.linalg.norm(atomRead))
        for nameSet,nameRead in zip(self.atoms,
                                    self.loader(1)['cellSymmetry'][2]):
            self.assertEqual(nameSet,nameRead)

    def test_loader_cell_symmetry_2(self):
        self.loader.parse()
        atoms      = [0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3]
        for directionSet,directionRead in zip(self.directions,
                                              self.loader(2)['cellSymmetry'][0]):
            self.assertAlmostEqual(np.linalg.norm(directionSet),
                                   np.linalg.norm(directionRead))
        for atomSet,atomRead in zip(self.cell,
                                    self.loader(2)['cellSymmetry'][1]):
            self.assertAlmostEqual(np.linalg.norm(atomSet),
                                   np.linalg.norm(atomRead))
        for nameSet,nameRead in zip(atoms,
                                    self.loader(2)['cellSymmetry'][2]):
            self.assertEqual(nameSet,nameRead)
Esempio n. 10
0
 def test_parse_constrains(self):
     constr = POSCARloader.parse_constrains(self.atom_input)
     self.assertIsNone(constr)
Esempio n. 11
0
 def test_parse_name_constrains(self):
     name = POSCARloader.parse_atom_name(self.atom_input_constr)
     self.assertEqual(name,'True')
Esempio n. 12
0
 def test_parse_name(self):
     name = POSCARloader.parse_atom_name(self.atom_input)
     self.assertEqual(name,'Cu')
Esempio n. 13
0
 def test_parse_atom_constrains(self):
     atom = POSCARloader.parse_atom(self.atom_input_constr)
     self.assertAlmostEqual(np.linalg.norm(atom-self.atom_constr_proper),0.0)
Esempio n. 14
0
 def setUp(self):
     self.loader   = POSCARloader('testData/POSCAR_exp1','testData/POSCAR_exp2','testData/POSCAR_exp3')
Esempio n. 15
0
        vaspFile.write("\n1.0\n")
        invDirections = np.linalg.inv(data['directions'])
        for direction in data['directions']:
            vaspFile.write(3*"  %.10f"%tuple(direction)+"\n")
        for atomName in data['atomNames']:
            vaspFile.write("%s "%atomName)
        vaspFile.write("\n")
        for atomNumber in data['cellAtoms']:
            vaspFile.write("%d "%atomNumber)
        if option == 'D':
            vaspFile.write("\nDirect\n")
        else:
            vaspFile.write("\nCarthesian\n")
        for atom in data['cell']:
            if option == 'D':
                vaspFile.write(3*" %.10f "%(*np.dot(invDirections,atom[1]),))
            else:
                vaspFile.write(3*" %.10f "%(*atom[1],))
            try:
                vaspFile.write(" %s\n"%data['atomNames'][atom[0]])
            except TypeError:
                vaspFile.write(" %s\n"%atom[0])
        vaspFile.write("\n")

if __name__ == '__main__':
    options = CommandLineOptions(*argv)
    for poscar in options('files'):
        loader = POSCARloader(poscar)
        loader.parse()
        save_vanilla_poscar('%s.fxd'%poscar,loader(),options('convert_to').capitalize()[0])