def test_init_pypospack(self):
        atoms = ase.build.bulk('Cu','fcc', cubic=True)
        sim_cell_init = crystal.SimulationCell(atoms)
        sim_cell_copy = crystal.SimulationCell(sim_cell_init)

        #check to see if we produce the correct object
        assert isinstance(sim_cell_copy,crystal.SimulationCell)

        #check to see if the lattice parameter is correct
        assert sim_cell_copy.a0 == sim_cell_init.a0

        #check to see that the H matrix is an nd.array
        assert isinstance(sim_cell_copy.H,np.ndarray)

        #check to see that the shape of the H matrix is correct
        assert sim_cell_copy.H.shape == (3,3)

        #check to see that the H matrix is correct
        for i in range(3):
            for j in range(3):
                assert abs(sim_cell_copy.H[i,j]-sim_cell_init.H[i,j]) < 1e-6

        #check to see that the number of atoms are correct
        assert len(sim_cell_init.atomic_basis) == len(sim_cell_copy.atomic_basis)

        for i,a in enumerate(sim_cell_init.atomic_basis):
            #check to see that the symbols are correct
            assert sim_cell_copy.atomic_basis[i].symbol == sim_cell_init.atomic_basis[i].symbol
            #check to see that the positions are correct
            direct_x_init = sim_cell_init.atomic_basis[i].position
            direct_x_final = sim_cell_copy.atomic_basis[i].position
            for j in range(3):
                assert abs(direct_x_init[j]-direct_x_final[j]) < 1e-6
    def test_init_ase_cell(self):
        atoms = ase.build.bulk('Cu','fcc', cubic=True)
        sim_cell = crystal.SimulationCell(atoms)

        #check to see if we produce the correct object
        assert isinstance(sim_cell,crystal.SimulationCell)

        #check to see that lattice parameter is correct
        assert sim_cell.a0 == 1
        #check to see that the H matrix is an nd.array
        assert isinstance(sim_cell.H,np.ndarray)

        #check to see that the shape of the H matrix is correct
        assert sim_cell.H.shape == (3,3)

        #check to see that the H matrix is correct
        for i in range(3):
            for j in range(3):
                assert abs(atoms.cell[i,j]-sim_cell.H[i,j]) < 1e-6

        #check to see that the number of atoms are correct
        assert len(atoms) == len(sim_cell.atomic_basis)

        #check to see that the positions are correct
        for i,a in enumerate(atoms):
            assert sim_cell.atomic_basis[i].symbol == a.symbol
            direct_x_ase = crystal.cartesian2direct(a.position,atoms.cell)
            direct_x_pypospack = sim_cell.atomic_basis[i].position
            for j in range(3):
                assert abs(direct_x_ase[j]-direct_x_pypospack[j]) < 1e-6
示例#3
0
def test_poscar_init_ppp():
    """ test if we can build from pypospack.crystal """
    symbol = 'Cu'
    sg = 'fcc'
    a = 3.6

    obj_ppp_1 = crystal.SimulationCell(
            ase.build.bulk(symbol,sg,a=a,cubic=True))
    obj_ppp_2 = vasp.Poscar(obj_ppp_1)
示例#4
0
def test_poscar_init_ase():
    """ test if we can build from ase """
    symbol = 'Cu'
    sg = 'fcc'
    a = 3.6

    obj_ppp = crystal.SimulationCell(
            ase.build.bulk(symbol,sg,a=a,cubic=True))

    poscar = vasp.Poscar(obj_ppp)
示例#5
0
class test_poscar_init_fcc_unit(unittest.TestCase):
    
    def setUp(self):
        self.symbol = 'Cu'
        self.sg = 'fcc'
        self.a = 3.6

    def test_poscar_init_ase(unittest.TestCase):
        """ test if we can build from ase """

        obj_ppp = crystal.SimulationCell(
                ase.build.bulk(symbol,sg,a=a,cubic=True))

        poscar = vasp.Poscar(obj_ppp)

        self.assert
示例#6
0
    def gulp_positions_to_string(self, structure='POSCAR'):
        """ returns the gulp position section to create simulation cell

        Args:
            structure (str): the filename of the POSCAR format file.  Default 
                is 'POSCAR'.  If an object which subclasses the 
                pyposmat.crystal.SimulationCell class is passed, this method
                will use this that class instead.

        Returns
            str:
        """

        sim_cell = None
        if isinstance(structure, crystal.SimulationCell):
            sim_cell = crystal.SimulationCell(poscar)
        else:
            sim_cell = vasp.Poscar()
            try:
                sim_cell.read(structure)
            except FileNotFoundError as e:
                msg = 'PYPOSPACK_ERROR: cannot find the POSCAR file:{}'.format(
                    structure)
                raise

        H = sim_cell.H * sim_cell.a0
        str_out = "vectors\n"
        str_out += "{:.10f} {:.10f} {:.10f}\n".format(H[0, 0], H[0, 1], H[0,
                                                                          2])
        str_out += "{:.10f} {:.10f} {:.10f}\n".format(H[1, 0], H[1, 1], H[1,
                                                                          2])
        str_out += "{:.10f} {:.10f} {:.10f}\n".format(H[2, 0], H[2, 1], H[2,
                                                                          2])
        str_out += "fractional\n"
        for s in sim_cell.symbols:
            for a in sim_cell.atomic_basis:
                if a.symbol == s:
                    try:
                        str_out += "{} core {} {} {}\n".format(\
                                s,a.position[0],a.position[1],a.position[2])
                    except:
                        print(s)
                        print(a.symbol)
                        print(a.position)
                        raise
        return str_out
 def test_add_atom(self):
     sim_cell = crystal.SimulationCell()
     sim_cell.add_atom('Cu',[0,0,0])
 def test_init_default(self):
     sim_cell = crystal.SimulationCell()
     assert isinstance(sim_cell,crystal.SimulationCell)
 def test_init_ase(self):
     atoms = ase.build.bulk('Cu','fcc', cubic=True)
     sim_cell = crystal.SimulationCell(atoms)
     assert isinstance(sim_cell,crystal.SimulationCell)
示例#10
0
        for i in range(3):
            for j in range(3):
                assert abs(sim_cell_copy.H[i,j]-sim_cell_init.H[i,j]) < 1e-6

        #check to see that the number of atoms are correct
        assert len(sim_cell_init.atomic_basis) == len(sim_cell_copy.atomic_basis)

        for i,a in enumerate(sim_cell_init.atomic_basis):
            #check to see that the symbols are correct
            assert sim_cell_copy.atomic_basis[i].symbol == sim_cell_init.atomic_basis[i].symbol
            #check to see that the positions are correct
            direct_x_init = sim_cell_init.atomic_basis[i].position
            direct_x_final = sim_cell_copy.atomic_basis[i].position
            for j in range(3):
                assert abs(direct_x_init[j]-direct_x_final[j]) < 1e-6

    def test_add_atom(self):
        sim_cell = crystal.SimulationCell()
        sim_cell.add_atom('Cu',[0,0,0])
if __name__ == "__main__":
    sim_cell = crystal.SimulationCell()
    print(sim_cell.a0)
    print(sim_cell.H)
    print(type(sim_cell.atomic_basis))
    for a in sim_cell.atomic_basis:
        print(a.symbol,a.position)

    print('add_atom')
    sim_cell.add_atom('Cu',[0,0,0])

"""
This script tests the functionality of the pypospack.io.phonts module by 
recreating the example in the PhonTS example/argon

"""
import copy
import numpy as np
import pypospack.io.phonts as phonts
import pypospack.crystal as crystal

# define simulation cell directly
ar_fcc = crystal.SimulationCell()
ar_fcc.a0 = 3.9620
ar_fcc.add_atom('Ar', [0.0, 0.0, 0.0])
ar_fcc.add_atom('Ar', [0.5, 0.5, 0.0])
ar_fcc.add_atom('Ar', [0.5, 0.0, 0.5])
ar_fcc.add_atom('Ar', [0.0, 0.5, 0.5])

# define simulation cell through poscar file
# poscar_filename = 'POSCAR'
# acc_fcc = vasp.Poscar()
# acc_fcc.read('POSCAR')

# this is a leonnard jones potential
# TODO: LJ is not currently implemented in pypospack.potentials
# TODO: pypospack.potentials.LeonnardJones.to_phonts_string() not implemented
phonts_potential_type = ['exp-6', 1]
phonts_potential_params = ['Ar', 'Ar', 0.010531316, 13., 3.85, 5.625, 9.625]

slurm_phonts_dict = {}
slurm_phonts_dict['filename'] = 'slurm_submit.sh'