示例#1
0
    def test_decimal(self):
        struct = Structure.from_str(
            """Mg2 Al4 O8
        1.0
        5.003532 0.000000 2.888790
        1.667844 4.717375 2.888790
        0.000000 0.000000 5.777581
        O Mg Al
        8 2 4
        direct
        0.736371 0.736371 0.736371 O
        0.263629 0.263629 0.709114 O
        0.263629 0.709114 0.263629 O
        0.709114 0.263629 0.263629 O
        0.736371 0.290886 0.736371 O
        0.290886 0.736371 0.736371 O
        0.263629 0.263629 0.263629 O
        0.736371 0.736371 0.290886 O
        0.125000 0.125000 0.125000 Mg
        0.875000 0.875000 0.875000 Mg
        0.500000 0.500000 0.000000 Al
        0.500000 0.500000 0.500000 Al
        0.000000 0.500000 0.500000 Al
        0.500000 0.000000 0.500000 Al""",
            fmt="poscar",
        )

        bp = BuckinghamPotential(bush_lewis_flag="bush")
        gio = GulpIO()
        input = gio.buckingham_input(struct, ["relax conp"])
        caller = GulpCaller()
        gout = caller.run(input)
示例#2
0
    def test_run(self):
        mgo_latt = [[4.212, 0, 0], [0, 4.212, 0], [0, 0, 4.212]]
        mgo_specie = ["Mg"] * 4 + ["O"] * 4
        mgo_frac_cord = [
            [0, 0, 0],
            [0.5, 0.5, 0],
            [0.5, 0, 0.5],
            [0, 0.5, 0.5],
            [0.5, 0, 0],
            [0, 0.5, 0],
            [0, 0, 0.5],
            [0.5, 0.5, 0.5],
        ]
        mgo_uc = Structure(mgo_latt, mgo_specie, mgo_frac_cord, True, True)
        gio = GulpIO()
        gin = gio.keyword_line("optimise", "conp")
        gin += gio.structure_lines(mgo_uc, symm_flg=False)
        # gin += self.gc.gulp_lib('catlow.lib')
        gin += "species\nMg    core  2.00000\nO core  0.86902\nO shel -2.86902\n"
        gin += "buck\n"
        gin += "Mg core O shel   946.627 0.31813  0.00000 0.0 10.0\n"
        gin += "O  shel O shel 22764.000 0.14900 27.87900 0.0 12.0\n"
        gin = gin
        gc = GulpCaller()

        """Some inherent checks are in the run_gulp function itself.
        They should be suffcient for raising errors."""
        gout = gc.run(gin)
示例#3
0
from pymatgen.command_line.gulp_caller import GulpIO
from MDAnalysis import Universe

gio = GulpIO()
gio
示例#4
0
from pymatgen import MPRester, Structure
from pymatgen.command_line.gulp_caller import GulpCaller, GulpIO
from matplotlib import pyplot

mpr = MPRester()
mono: Structure = mpr.get_structure_by_material_id('mp-352')
ortho: Structure = mpr.get_structure_by_material_id('mp-685097')
tetra: Structure = mpr.get_structure_by_material_id('mp-1018721')
gio = GulpIO()
gc = GulpCaller()
for i in [mono, ortho, tetra]:
    arr = []
    arr2 = []
    i.apply_strain(-.05)
    for j in range(15):
        gin = gio.buckingham_input(i, ['conv'], library='morse.lib', alib=True)
        gout = gc.run(gin)
        arr.append(i.density)
        arr2.append(gio.get_energy(gout))
        i.apply_strain(-.01)
    i.to('POSCAR', i.get_space_group_info()[0].replace('/', '_') + '.vasp')
    if i.get_space_group_info()[0] == 'P4_2/nmc':
        pyplot.plot(arr, [r * 2 for r in arr2],
                    label=i.get_space_group_info()[0])
    else:
        pyplot.plot(arr, arr2, label=i.get_space_group_info()[0])
pyplot.legend()
pyplot.show()
示例#5
0
class GulpIOTest(unittest.TestCase):
    _multiprocess_shared_ = True

    def setUp(self):
        p = Poscar.from_file(
            os.path.join(PymatgenTest.TEST_FILES_DIR, "POSCAR.Al12O18"), check_for_POTCAR=False
        )
        self.structure = p.structure
        self.gio = GulpIO()

    def test_keyword_line_with_correct_keywords(self):
        kw = ("defect", "property")
        inp_str = self.gio.keyword_line(*kw)
        for word in kw:
            self.assertIn(word, inp_str)

    def test_structure_lines_default_options(self):
        inp_str = self.gio.structure_lines(self.structure)
        self.assertIn("cell", inp_str)
        self.assertIn("frac", inp_str)
        self.assertIn("space", inp_str)

    def test_structure_lines_no_unitcell(self):
        inp_str = self.gio.structure_lines(self.structure, cell_flg=False)
        self.assertNotIn("cell", inp_str)

    def test_structure_lines_no_frac_coords(self):
        inp_str = self.gio.structure_lines(
            self.structure, cell_flg=False, frac_flg=False
        )
        self.assertNotIn("cell", inp_str)
        self.assertIn("cart", inp_str)

    @unittest.skip("Not Implemented yet")
    def test_specie_potential(self):
        pass

    @unittest.expectedFailure
    def test_library_line_explicit_path(self):
        gin = self.gio.library_line(
            "/Users/mbkumar/Research/Defects/GulpExe/Libraries/catlow.lib"
        )
        self.assertIn("lib", gin)

    def test_library_line_wrong_file(self):
        with self.assertRaises(GulpError):
            gin = self.gio.library_line("temp_to_fail.lib")

    def test_buckingham_potential(self):
        mgo_latt = [[4.212, 0, 0], [0, 4.212, 0], [0, 0, 4.212]]
        mgo_specie = ["Mg", "O"] * 4
        mgo_frac_cord = [
            [0, 0, 0],
            [0.5, 0, 0],
            [0.5, 0.5, 0],
            [0, 0.5, 0],
            [0.5, 0, 0.5],
            [0, 0, 0.5],
            [0, 0.5, 0.5],
            [0.5, 0.5, 0.5],
        ]
        mgo_uc = Structure(mgo_latt, mgo_specie, mgo_frac_cord, True, True)
        gin = self.gio.buckingham_potential(mgo_uc)
        self.assertIn("specie", gin)
        self.assertIn("buck", gin)
        self.assertIn("spring", gin)
        self.assertIn("Mg core", gin)
        self.assertIn("O  core", gin)
        self.assertIn("O  shel", gin)

        gin = self.gio.buckingham_potential(self.structure)
        self.assertIn("specie", gin)
        self.assertIn("buck", gin)
        self.assertIn("spring", gin)

    def test_buckingham_input(self):
        mgo_latt = [[4.212, 0, 0], [0, 4.212, 0], [0, 0, 4.212]]
        mgo_specie = ["Mg", "O"] * 4
        mgo_frac_cord = [
            [0, 0, 0],
            [0.5, 0, 0],
            [0.5, 0.5, 0],
            [0, 0.5, 0],
            [0.5, 0, 0.5],
            [0, 0, 0.5],
            [0, 0.5, 0.5],
            [0.5, 0.5, 0.5],
        ]
        mgo_uc = Structure(mgo_latt, mgo_specie, mgo_frac_cord, True, True)
        gin = self.gio.buckingham_input(mgo_uc, keywords=("optimise", "conp"))
        self.assertIn("optimise", gin)
        self.assertIn("cell", gin)
        self.assertIn("specie", gin)
        self.assertIn("buck", gin)
        self.assertIn("spring", gin)
        self.assertIn("Mg core", gin)
        self.assertIn("O  core", gin)
        self.assertIn("O  shel", gin)

    # Improve the test
    def test_tersoff_potential(self):
        mgo_latt = [[4.212, 0, 0], [0, 4.212, 0], [0, 0, 4.212]]
        mgo_specie = ["Mg", "O"] * 4
        mgo_frac_cord = [
            [0, 0, 0],
            [0.5, 0, 0],
            [0.5, 0.5, 0],
            [0, 0.5, 0],
            [0.5, 0, 0.5],
            [0, 0, 0.5],
            [0, 0.5, 0.5],
            [0.5, 0.5, 0.5],
        ]
        mgo_uc = Structure(mgo_latt, mgo_specie, mgo_frac_cord, True, True)
        gin = self.gio.tersoff_potential(mgo_uc)
        self.assertIn("specie", gin)
        self.assertIn("Mg core", gin)

    def test_get_energy(self):
        # Output string obtained from running GULP on a terminal
        out_str = """  Components of energy :
--------------------------------------------------------------------------------
  Interatomic potentials     =           5.61135426 eV
  Monopole - monopole (real) =          -4.34238722 eV
  Monopole - monopole (recip)=         -43.45344934 eV
  Monopole - monopole (total)=         -47.79583656 eV
--------------------------------------------------------------------------------
  Total lattice energy :
    Primitive unit cell      =         -42.18448230 eV
    Non-primitive unit cell  =        -168.73792920 eV
--------------------------------------------------------------------------------
  Total lattice energy (in kJmol-1):
    Primitive unit cell      =           -4070.1577 kJ/(mole unit cells)
    Non-primitive unit cell  =          -16280.6308 kJ/(mole unit cells)
--------------------------------------------------------------------------------
  Components of energy :

--------------------------------------------------------------------------------
  Interatomic potentials     =           6.79846039 eV
  Monopole - monopole (real) =          -4.45761741 eV
  Monopole - monopole (recip)=         -44.60653603 eV
  Monopole - monopole (total)=         -49.06415344 eV
--------------------------------------------------------------------------------
  Total lattice energy :
    Primitive unit cell      =         -42.26569304 eV
    Non-primitive unit cell  =        -169.06277218 eV
--------------------------------------------------------------------------------
  Total lattice energy (in kJmol-1):
    Primitive unit cell      =           -4077.9933 kJ/(mole unit cells)
    Non-primitive unit cell  =          -16311.9732 kJ/(mole unit cells)
--------------------------------------------------------------------------------"""
        energy = self.gio.get_energy(out_str)
        self.assertEqual(energy, -169.06277218)

    def test_get_relaxed_structure(self):
        # Output string obtained from running GULP on a terminal

        with open(os.path.join(PymatgenTest.TEST_FILES_DIR, "example21.gout"), "r") as fp:
            out_str = fp.read()
        struct = self.gio.get_relaxed_structure(out_str)
        self.assertIsInstance(struct, Structure)
        self.assertEqual(8, len(struct.sites))
        self.assertEqual(4.212, struct.lattice.a)
        self.assertEqual(90, struct.lattice.alpha)

    @unittest.skip("Test later")
    def test_tersoff_inpt(self):
        gin = self.gio.tersoff_input(self.structure)
示例#6
0
 def setUp(self):
     p = Poscar.from_file(
         os.path.join(PymatgenTest.TEST_FILES_DIR, "POSCAR.Al12O18"), check_for_POTCAR=False
     )
     self.structure = p.structure
     self.gio = GulpIO()
示例#7
0
from scipy.io import FortranFile
import numpy as np
from pymatgen.command_line.gulp_caller import GulpIO
gio = GulpIO()
gio.get_iniitial_structure(
    '/home/jinho93/slab/LAO/grimes/nvt/dense/report.gulp')
fortran = False
if fortran:
    with FortranFile('/home/jinho93/slab/LAO/bush/nvt/island/old/md.trg') as f:
        version = f.read_reals()[0]
        n_atoms, ndim = f.read_ints()
        print(f'Version is {version}\nn_atoms is {n_atoms}, ndim is {ndim}')
        n_frames = 3
        for _ in range(n_frames):
            tket = f.read_reals()
            tket = [f'{r:.02f}' for r in tket]
            print(f'Time/KE/E/T {tket}')
            for l in range(10):
                line = f.read_reals()
                print(len(line))
else:
    with open('/home/jinho93/slab/LAO/grimes/nvt/dense/lao.trg') as f:
        version = f.readline()
        n_atoms, ndim = [int(r) for r in f.readline().split()]
        print(f'Version is {version}\nn_atoms is {n_atoms}, ndim is {ndim}')
        n_frames = 1

        for _ in range(n_frames):
            x, y, z = np.zeros(n_atoms), np.zeros(n_atoms), np.zeros(n_atoms)
            vx, vy, vz = np.zeros(n_atoms), np.zeros(n_atoms), np.zeros(
                n_atoms)
示例#8
0
from pymatgen import Structure
from pymatgen.command_line.gulp_caller import GulpIO, GulpCaller
import sys
path = '/home/jinho93/slab/LAO/nvt/line/'
path = '/home/jinho93/interface/tin-hfo2-tio2/gulp'
s: Structure = Structure.from_file(path + '/POSCAR')
gio = GulpIO()
sys.stdout = open(path + 'md.gin', 'w')
print(gio.buckingham_input(s, keywords=['conv', 'md', 'qok']))
gio.structure_lines(s, anion_shell_flg=False)
示例#9
0
from pymatgen.command_line.gulp_caller import GulpIO, Structure
from pymatgen.io.xyz import XYZ
gio = GulpIO()
name = 'C'
path = f'/home/share/SiCOH/{name}'
with open(path + '/md.gin', 'w') as f:
    s = Structure.from_file(path + f'/{name}.cif')
    f.write(gio.structure_lines(s))
示例#10
0
from pymatgen.command_line.gulp_caller import GulpIO

gio = GulpIO()
with open('/home/jinho93/slab/LAO/grimes/nvt/dense/report.gulp') as f:
    s = gio.get_iniitial_structure(f.read())
    print(s)
示例#11
0
from pymatgen.command_line.gulp_caller import GulpCaller, GulpIO
from matplotlib import pyplot
import numpy as np

gio = GulpIO()
gc = GulpCaller()
arr = []
for i in np.linspace(0.5, 1, 100):
    body = f'''conv
#cell
#1 1 10 90 90 90
cart
O core 0 0 -{i}
O core 0 0 {i}
Hf core 0 0 0
species
Hf core  2.4
O  core -1.2
general 0 12
Hf core O core 0 0 1.0 1.
'''
    gout = gc.run(body)
    e = gio.get_energy(gout)
    arr.append(e)
pyplot.plot(arr)
pyplot.show()
示例#12
0
    with zopen(filen, "rt") as f:
        contents = f.read()
    energy = Gulp.get_energy(contents)
    if lave:
        contents = open(filen, 'r').readlines()
        for line in contents:
            if 'Total number atoms/shells' in line:
                num = int(re.findall('\d+', line)[0])
                break
    else:
        num = 1
    return energy / num


if __name__ == '__main__':
    Gulp = GulpIO()

    num = int(sys.argv[1])
    if num == 1:
        #write input file of gulp
        Cry_Str = Structure.from_file("POSCAR")
        with open('gulpinput', 'w') as f:
            f.write(Gulp.keyword_line('opti conj conp nosymmetry qok'))
            f.write(Gulp.keyword_line('switch_min bfgs gnorm 0.5\n'))

            gulpinput = Gulp.structure_lines(structure=Cry_Str, symm_flg=False)
            f.write(gulpinput)

            f.write(Gulp.keyword_line('maxcyc 500'))
            f.write(Gulp.keyword_line('library self_build.lib'))
            f.write(Gulp.keyword_line('dump every gulpopt'))
示例#13
0
#%%

from pymatgen import Molecule, Structure
import os
import numpy as np
from pymatgen.core.lattice import Lattice

os.chdir('/home/jinho93/oxides/perobskite/lanthanum-aluminate/slab/nvt.para.6/island/len-19/step1')

s = Molecule.from_file('POSCAR.xyz')
sp = []
coords = []
for i in s.sites:
    if i.x < 7 and i.y < 7:
        sp.append(i.specie)
        coords.append(i.coords)
        
new = Structure(Lattice(np.identity(3) * 7.648200),sp, coords, coords_are_cartesian=True)
new.to('POSCAR', 'ini_pot/reduced')

# %%

#%%

from pymatgen.command_line.gulp_caller import GulpIO
gio = GulpIO()
gio.buckingham_input(new, keywords=['conv'], uc=False)

# %%
示例#14
0
 def setUp(self):
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.Al12O18'),
                          check_for_POTCAR=False)
     self.structure = p.structure
     self.gio = GulpIO()
示例#15
0
#!/usr/bin/python2
#Change the format of crystal structure
#python Str_Format.py infile outfile
try:
    from pymatgen.io.vasp.inputs import Poscar
    from pymatgen import Structure
    from pymatgen.command_line.gulp_caller import GulpIO
except:
    print 'You should install pymatgen first.'
    exit(0)

import sys
from monty.io import zopen

if __name__ == '__main__':
    Gulp = GulpIO()

    #change the Structure
    #Cry_Str = Structure.from_file("POSCAR")
    #gulpinput = Gulp.structure_lines(structure = Cry_Str)
    #with open('gulpinput','w') as f:
    #f.write(gulpinput)
    #exit(0)

    #output the energy
    with zopen('log', "rt") as f:
        contents = f.read()
    energy = Gulp.get_energy(contents)
    print energy

    #output the relaxed structure