Example #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)
Example #2
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()
Example #3
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)
Example #4
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)
Example #5
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)

# %%