예제 #1
0
 def __init__(self, simulation_path="."):
     self.simulation_path = simulation_path
     self.poscar = Poscar()
     self.incar = Incar()
     self.kpoints = Kpoints()
     self.potcar = Potcar()
     self.submission_script = SlurmSubmissionScript()
예제 #2
0
def test__no_charges():
    filename = os.path.join(
            'test__simulation_cell_to_phonts_string',
            'Si_dia_unit.relax.gga.vasp')
    poscar = Poscar()
    poscar.read(filename=filename)

    from pypospack.io.phonts import simulation_cell_to_phonts_string
    simulation_cell_to_phonts_string(
            simulation_cell=poscar)
from pypospack.io.vasp import Poscar
from pypospack.crystal import make_super_cell

_bulk_filename = "Ni_fcc_110_unit.gga.relaxed.vasp"
_bulk_poscar = Poscar()
_bulk_poscar.read(_bulk_filename)
_surface_filename = "Ni_fcc_110_surf.vasp"
_surface_sc = [1, 1, 10]
_surface_sc = Poscar(make_super_cell(_bulk_poscar, _surface_sc))
_surface_slab_pct_of_z = 0.5
_surface_slab_thickness = _surface_sc.a3 * _surface_slab_pct_of_z

atoms_to_remove = []
for a in _surface_sc.atomic_basis:
    print(a.position, a.position[2] < _surface_slab_pct_of_z)
    if not a.position[2] < _surface_slab_pct_of_z:
        atoms_to_remove.append([a.symbol, list(a.position)])

for a in atoms_to_remove:
    symbol = a[0]
    position = a[1]
    print('removing {} atom @ {}'.format(str(a[0]), str(a[1])))
    _surface_sc.remove_atom(symbol=symbol, position=position)

for a in _surface_sc.atomic_basis:
    print(a.symbol, a.position)

_surface_sc.write(_surface_filename)
예제 #4
0
import argparse
from pypospack.io.vasp import Poscar
_description = 'Normalizes the H-matrix'
_parser = argparse.ArgumentParser(description=_description)
_parser.add_argument('--in', action='store', dest='filename_in', type=str)
_parser.add_argument('--out', action='store', dest='filename_out', type=str)

_args = _parser.parse_args()
_filename_in = _args.filename_in
_filename_out = _args.filename_out

print('filename_in:{}'.format(_filename_in))
_poscar = Poscar()
_poscar.read(_filename_in)
print('a0:{}'.format(_poscar.a0))
print('H:\n{}'.format(_poscar.H))
print('filename_out:{}'.format(_filename_out))
_poscar.normalize_h_matrix()
print(80 * '-')
print('a0:{}'.format(_poscar.a0))
print('H:\n{}'.format(_poscar.H))
_poscar.write(_filename_out)
예제 #5
0
    _latticeconstant = {}
    _latticeconstant['a'] = 5.022  # Angs
    _latticeconstant['b'] = 5.022  # Angs
    _latticeconstant['c'] = 5.511  # Angs
    _latticeconstant['alpha'] = 90  #deg
    _latticeconstant['beta'] = 90  # degrees
    _latticeconstant['gamma'] = 120  # degrees

    # make ASE structure
    from ase import Atoms, Atom
    SiO2_aq = SiO2_a_quartz(directions=_directions,
                            size=(1, 1, 1),
                            symbol=('Si', 'O'),
                            latticeconstant=_latticeconstant)

    # convert to pypospack.crystal.SimulationCell
    from pypospack.crystal import SimulationCell
    SiO2_pyp = SimulationCell(SiO2_aq)

    # write the poscar file
    from pypospack.io.vasp import Poscar
    SiO2_poscar = Poscar(SiO2_pyp)
    SiO2_poscar.write('SiO2_aq_cubic.vasp')

    # write lammps structure
    from pypospack.io.lammps import LammpsStructure
    SiO2_lammps = LammpsStructure(SiO2_pyp)
    SiO2_lammps.write(filename='SiO2_aq_cubic.lammps',
                      symbol_list=['Si', 'O'],
                      atom_style='charge')  #or 'atomic'
예제 #6
0
        print(
            '...deleting directory and contents {}'.format(dst_structure_dir))
        print('...recreating the directory {}'.format(dst_structure_dir))
        shutil.rmtree(dst_structure_dir)
        os.mkdir(dst_structure_dir)
    else:
        print('dst_structure_dir does not exist...')
        print('...creating the directory {}'.format(dst_structure_dir))
        os.mkdir(dst_structure_dir)

    for k, v in structures.items():
        # convert ase -> pypospack
        v['pypospack_obj'] = SimulationCell(v['ase_obj'])
        # convert pypospack -> VASP poscar
        if is_write_vasp_structures:
            v['vasp_obj'] = Poscar(v['pypospack_obj'])
            v['vasp_fname'] = '{}.vasp'.format(k)
            v['vasp_obj'].write(
                os.path.join(dst_structure_dir, v['vasp_fname']))
            print('{}->{}'.format(k, v['vasp_fname']))

        # convert pypospack -> LAMMPS structure
        if is_write_lammps_structures:
            v['lammps_obj'] = LammpsStructure(v['pypospack_obj'])
            v['lammps_fname'] = '{}.structure'.format(k)
            v['lammps_obj'].write(filename=os.path.join(
                dst_structure_dir, v['lammps_fname']),
                                  symbol_list=v['symbol_list'],
                                  atom_style=v['lmps_atom_style'])
            print('{}->{}'.format(k, v['lammps_fname']))
예제 #7
0
import ase.build
import numpy as np
from pypospack.crystal import SimulationCell


class DiamondStructure(SimulationCell):
    def __init__(self, symbols=['Si'], a=5.43):

        assert isinstance(symbols, list)
        assert len(symbols) == 1

        SimulationCell.__init__(self)
        self.H = np.array([[a, 0, 0], [0, a, 0], [0, 0, a]])
        self.add_atom(symbol=symbols[0], position=[0.0, 0.0, 0.0])
        self.add_atom(symbol=symbols[0], position=[0.25, 0.25, 0.25])
        self.add_atom(symbol=symbols[0], position=[0.00, 0.50, 0.50])
        self.add_atom(symbol=symbols[0], position=[0.25, 0.75, 0.75])
        self.add_atom(symbol=symbols[0], position=[0.50, 0.00, 0.50])
        self.add_atom(symbol=symbols[0], position=[0.75, 0.25, 0.75])
        self.add_atom(symbol=symbols[0], position=[0.50, 0.50, 0.00])
        self.add_atom(symbol=symbols[0], position=[0.75, 0.75, 0.25])


if __name__ == "__main__":
    from pypospack.io.vasp import Poscar
    filename = "Si_dia_unit.vasp"

    cell = DiamondStructure(symbols=['Si'], a=5.43)
    poscar = Poscar(obj_cell=DiamondStructure(symbols=['Si'], a=5.43))
    poscar.write(filename=filename)
예제 #8
0
                x = copy.deepcopy(a.position)
                x[0] = x[0] / simulation_cell.H[0, 0]
                x[1] = x[1] / simulation_cell.H[1, 1]
                x[2] = n * layer_spacing / simulation_cell.H[2, 2]
                simulation_cell.add_atom(s, x)
    return simulation_cell


if __name__ == "__main__":
    from pypospack.io.vasp import Poscar
    # INTRINSIC STACKING FAULT
    symbols = ['Ni']
    stacking_sequence = "ABC,ABC,AC,ABC,ABC"
    simulation_cell = make_fcc_stacking_fault(symbols, stacking_sequence)
    simulation_cell.normalize_h_matrix()
    poscar = Poscar(simulation_cell)
    poscar.write('Ni_fcc_isf.vasp')

    symbols = ['Ni']
    stacking_sequence = "ABC,ABC,ABAC,ABC,ABC"
    simulation_cell = make_fcc_stacking_fault(symbols, stacking_sequence)
    simulation_cell.normalize_h_matrix()
    poscar = Poscar(simulation_cell)
    poscar.write('Ni_fcc_esf.vasp')

    symbols = ['Ni']
    stacking_sequence = "ABC,ABC,AABC,ABC,ABC"
    simulation_cell = make_fcc_stacking_fault(symbols, stacking_sequence)
    simulation_cell.normalize_h_matrix()
    poscar = Poscar(simulation_cell)
    poscar.write('Ni_fcc_usf.vasp')
예제 #9
0
""" make FCC structure for silicon """

from pypospack.crystal import SimulationCell
import numpy as np


class BodyCenteredCubicStructure(SimulationCell):
    def __init__(self, symbols=['Ni'], a=3.52):
        assert isinstance(symbols, list)
        assert len(symbols) == 1

        SimulationCell.__init__(self)
        self.H = np.array([[a, 0, 0], [0, a, 0], [0, 0, a]])

        self.add_atom(symbol=symbols[0], position=[0.0, 0.0, 0.0])
        self.add_atom(symbol=symbols[0], position=[0.5, 0.5, 0.5])


if __name__ == "__main__":
    from pypospack.io.vasp import Poscar

    # For Si, in fcc phase
    # Pizzagalli
    # LDA calculations
    a = 3.42

    filename = 'Si_bcc.vasp'
    poscar = Poscar(obj_cell=BodyCenteredCubicStructure(symbols=['Si'], a=a))
    poscar.write(filename=filename)
예제 #10
0
class VaspSimulation():
    def __init__(self, simulation_path="."):
        self.simulation_path = simulation_path
        self.poscar = Poscar()
        self.incar = Incar()
        self.kpoints = Kpoints()
        self.potcar = Potcar()
        self.submission_script = SlurmSubmissionScript()

    @property
    def symbols(self):
        return self.incar.symbols

    @property
    def xc(self):
        return self.potcar.xc

    @xc.setter
    def xc(self, xc):
        self.potcar.xc = xc

    def read_incar(self, filename=None):
        if filename is None:
            filename_ = os.path.join(self.simulation_path, "INCAR")
        else:
            filename_ = filename

        self.incar.read(filename=filename_)

    def write_incar(self, filename=None):
        if filename is None:
            filename_ = os.path.join(self.simulation_path, "INCAR")
        else:
            filename_ = filename

        self.incar.write(filename=filename_)

    def write_poscar(self, filename=None):
        if filename is None:
            filename_ = os.path.join(self.simulation_path, "POSCAR")
        else:
            filename_ = filename

        self.poscar.write(filename=filename_)

    def write_potcar(self, xc='GGA', filename=None):
        self.xc = xc

        if filename is None:
            filename_ = os.path.join(self.simulation_path, 'POTCAR')
        else:
            filename_ = filename

        self.potcar.symbols = self.symbols
        self.potcar.write(filename=filename_)

    def write_kpoints(self, filename=None):
        if filename is None:
            filename_ = os.path.join(self.simulation_path, "KPOINTS")
        else:
            fiename_ = filename

        self.kpoints.write(filename_)

    def write_submission_script(self, filename=None):
        if filename is None:
            filename_ = os.path.join(self.simulation_path, "runjob.slurm")
        else:
            filename_ = filename

        self.simulation_script.write(filename=filename_)

    def write(self, path, is_clobber=False):
        self.simulation_path = path

        try:
            os.path.mkdir(path)
        except FileExistsError as e:
            if is_clobber:
                shutil.rmthree(path)
                os.path.mkdir(path)
            else:
                raise

        self.write_poscar()
        self.write_potcar()
        self.write_incar()
        self.write_kpoints()
        self.write_submission_script()
예제 #11
0
import numpy as np


class BetaTinStructure(SimulationCell):
    def __init__(self, symbols=['Pb'], a=5.8315, c=3.1814):
        assert isinstance(symbols, list)
        assert len(symbols) == 1
        SimulationCell.__init__(self)
        self.H = np.array([[a, 0, 0], [0, a, 0], [0, 0, c]])

        self.add_atom(symbol=symbols[0], position=[0., 0., 0.])
        self.add_atom(symbol=symbols[0], position=[0.5, 0.0, 0.75])
        self.add_atom(symbol=symbols[0], position=[0.5, 0.5, 0.5])
        self.add_atom(symbol=symbols[0], position=[0.0, 0.5, 0.25])


if __name__ == "__main__":
    from pypospack.io.vasp import Poscar

    # For Si, in beta-pb phase
    #
    # 10.1103/PhysRevB.83.075119
    a = 4.81
    c_over_a = 0.552
    c = a * c_over_a

    filename = 'Si_betaPb.vasp'

    poscar = Poscar(obj_cell=BetaTinStructure(symbols=['Si'], a=a, c=c))
    poscar.write(filename=filename)
예제 #12
0
        self.add_atom(symbol=symbol, position=[0.500000, 0.000000, 0.500000])
        self.add_atom(symbol=symbol, position=[0.000000, 0.500000, 0.500000])
        self.add_atom(symbol=symbol, position=[0.500000, 0.500000, 0.000000])
        self.add_atom(symbol=symbol, position=[0.750000, 0.250000, 0.750000])
        self.add_atom(symbol=symbol, position=[0.750000, 0.750000, 0.250000])

    def initialize_primitive_cell(self, symbol='Si', a0=5.431):
        self.a0 = a0
        a1 = 1 / 2 * np.array([0, 1, 1])
        a2 = 1 / 2 * np.array([1, 0, 1])
        a3 = 1 / 2 * np.array([1, 1, 0])
        self.H = np.stack((a1, a2, a3))
        self.add_atom(symbol=symbol, position=[0.7500, 0.75000, 0.75000])
        self.add_atom(symbol=symbol, position=[0.5000, 0.50000, 0.50000])


if __name__ == "__main__":
    from pypospack.io.vasp import Poscar

    o = Poscar(obj_cell=Diamond(symbols=['Si'], a0=5.431, cell_type='cubic'))
    o.write(filename="Si_dia_unit.vasp")

    o = Poscar(
        obj_cell=Diamond(symbols=['Si'], a0=5.431, cell_type='primitive'))
    o.write(filename='Si_dia_prim.vasp')

    o = Diamond(symbols=['Si'], a0=5.431, cell_type='primitive')
    print(o.b1)
    print(o.b2)
    print(o.b3)
예제 #13
0
def test__setup__can_read_poscar_file():
    filename = os.path.join(
            'test__simulation_cell_to_phonts_string',
            'Si_dia_unit.relax.gga.vasp')
    poscar = Poscar()
    poscar.read(filename=filename)
예제 #14
0
def test__setup__can_read_poscar_file():
    filename = os.path.join(
            'test__simulation_cell_to_phonts_string',
            'Si_dia_unit.relax.gga.vasp')
    poscar = Poscar()
    poscar.read(filename=filename)

def test__no_charges():
    filename = os.path.join(
            'test__simulation_cell_to_phonts_string',
            'Si_dia_unit.relax.gga.vasp')
    poscar = Poscar()
    poscar.read(filename=filename)

    from pypospack.io.phonts import simulation_cell_to_phonts_string
    simulation_cell_to_phonts_string(
            simulation_cell=poscar)

if __name__ == "__main__":
    # creating tests for formatting is difficult.
    # it's better to do integration tests later to determine if
    # file created is valid.
    from pypospack.io.phonts import simulation_cell_to_phonts_string
    poscar = Poscar()
    poscar.read(filename='Si_dia_unit.relax.gga.vasp')
    cell_str= simulation_cell_to_phonts_string(
            simulation_cell=poscar)
    print(cell_str)

예제 #15
0
    # Basic idea = triple loop over all nearby image, pick shortest relative vector.
    # This is horribly slow, and for very skewed cells, n has to become very large.
    result = None
    n = 2
    for i0 in range(-n, n+1):
        for i1 in range(-n, n+1):
            for i2 in range(-n, n+1):
                rp = r+np.dot(a0*H.T, [i0,i1,i2])
                d = np.linalg.norm(rp)
                if (result is None) or (result[1] > d):
                    result = (rp, d)
    return result[0]

poscar_filename = 'Ni_fcc_unit.gga.relaxed.vasp'
cell_poscar = Poscar()
cell_poscar.read(poscar_filename)
cell_poscar.normalize_h_matrix()
cell_sc = make_super_cell(structure=cell_poscar,sc=[3,3,3])
_positions = [a.position for a in cell_sc.atomic_basis]
_n_atoms = len(_positions)
min_distances = []
for i in range(1,_n_atoms):
    r1 = np.array(_positions[0])
    r2 = np.array(_positions[i])
    r = r2-r1
    r_min = brute_minimum_image_convention(r=r,H=cell_sc.H,a0=cell_sc.a0)
    d = np.linalg.norm(r_min)
    min_distances.append(d*cell_poscar.a0*cell_poscar.a1)
min_distances = np.array(min_distances)
distances = np.linspace(
예제 #16
0
from pypospack.io.vasp import Poscar
from pypospack.crystal import make_super_cell

_bulk_filename = "Ni_fcc_111_unit.gga.relaxed.vasp"
_bulk_poscar = Poscar()
_bulk_poscar.read(_bulk_filename)
_isf_filename = "Ni_fcc_isf.vasp"
print('a1', _bulk_poscar.a1)
print('a1', _bulk_poscar.a2)
print('a1', _bulk_poscar.a3)

_isf_sc = [1, 1, 5]
_isf_sc = Poscar(make_super_cell(_bulk_poscar, _isf_sc))
import numpy as np
_isf_sc.H[2, 2] = _isf_sc.H[2, 2] * 0.933333
for a in _isf_sc.atomic_basis:
    a.position[2] = a.position[2] / 0.933333
_isf_sc.write(_isf_filename)
예제 #17
0
                    latticeconstant=_lattice_constants)
        else:
            raise
    return atoms


if __name__ == "__main__":
    Ni_fcc_100_unit = OrderedDict()
    Ni_fcc_100_unit['name'] = 'Ni_fcc_100'
    Ni_fcc_100_unit['symbols'] = ['Ni']
    Ni_fcc_100_unit['filename_prefix'] = 'Ni_fcc_100_unit'
    Ni_fcc_100_unit['ase'] = make_fcc_100_cell(
        symbols=Ni_fcc_100_unit['symbols'])
    Ni_fcc_100_unit['poscar_filename'] = '{}.vasp'.format(
        Ni_fcc_100_unit['filename_prefix'])
    Ni_fcc_100_unit['poscar'] = Poscar(Ni_fcc_100_unit['ase'])
    Ni_fcc_100_unit['poscar'].normalize_h_matrix()
    Ni_fcc_100_unit['poscar'].write(
        filename=Ni_fcc_100_unit['poscar_filename'])

    Ni_fcc_110_unit = OrderedDict()
    Ni_fcc_110_unit['name'] = 'Ni_fcc_110'
    Ni_fcc_110_unit['symbols'] = ['Ni']
    Ni_fcc_110_unit['filename_prefix'] = 'Ni_fcc_110_unit'
    Ni_fcc_110_unit['ase'] = make_fcc_110_cell(
        symbols=Ni_fcc_110_unit['symbols'])
    Ni_fcc_110_unit['poscar_filename'] = '{}.vasp'.format(
        Ni_fcc_110_unit['filename_prefix'])
    Ni_fcc_110_unit['poscar'] = Poscar(Ni_fcc_110_unit['ase'])
    Ni_fcc_100_unit['poscar'].normalize_h_matrix()
    Ni_fcc_110_unit['poscar'].write(