Exemple #1
0
def test_lammps_dump():
    sys = pc.System()
    sys.read_inputfile('tests/conf.dump')
    atoms = sys.get_allatoms()
    assert len(atoms) == 500

    #check box
    assert sys.get_box() == [[-7.66608, 11.1901],[-7.66915, 11.1931],[-7.74357, 11.2676]]
    
    #check few atoms
    filtered_atoms = [ atom for atom in atoms if atom.get_id() == 204]
    assert filtered_atoms[0].get_x() == [-0.10301, -6.35752, -6.44787]

    #now check the same for zipped file
    sys = pc.System()
    sys.read_inputfile('tests/conf.dump.gz')
    atoms = sys.get_allatoms()
    assert len(atoms) == 500

    #check box
    assert sys.get_box() == [[-7.66608, 11.1901],[-7.66915, 11.1931],[-7.74357, 11.2676]]
    
    #check few atoms
    filtered_atoms = [ atom for atom in atoms if atom.get_id() == 204]
    assert filtered_atoms[0].get_x() == [-0.10301, -6.35752, -6.44787]
Exemple #2
0
def test_system_nucsize():
    #create some atoms
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [2, 2, 2])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)

    #test that atoms are set properly
    assert len(sys.get_allatoms()) == 16

    #now calculate nucsize
    sys.set_nucsize_parameters(0.867, 6, 0.5, 0.5)
    #sys.calculate_nucsize()
    assert sys.calculate_nucsize() == 16

    #check the atom cluster props
    atoms = sys.get_allatoms()
    atom = atoms[0]
    cluster = atom.get_cluster()
    assert atom.get_cluster() == [1,0,1,1]
    assert sys.get_largestcluster() == 1
    #assert np.round(sys.get_connection(atoms[0], atoms[1]), decimals=2) == 1.00

    #nothing to assert - just check if it works
    sys.calculate_frenkelnumbers()
    sys.find_clusters()
    assert sys.find_largest_cluster() == 16
Exemple #3
0
def test_neighbors_system_filter():
    #create some atoms
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [2, 2, 2])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)


    sys.get_neighbors(method = 'cutoff', cutoff=0.867)
    #any atom should have 8 neighbors
    atoms = sys.get_allatoms()
    assert atoms[0].get_coordination() == 8

    #now we take all the neighbors of atom0 and replace half of
    #them with a different type
    neighs = atoms[0].get_neighbors()

    #replace the neighs
    atoms[neighs[0]].set_type(2)
    atoms[neighs[1]].set_type(2)

    #now set these atoms back
    #for atom in atoms:
    sys.set_atom(atoms[neighs[0]])
    sys.set_atom(atoms[neighs[1]])

    #recalculate neighbors with filter
    sys.get_neighbors(method = 'cutoff', cutoff=0.867, filter='type')
    #any atom should have 8 neighbors
    atoms = sys.get_allatoms()
    assert atoms[0].get_coordination() == 6
Exemple #4
0
def test_q_4():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[4, 4, 4])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)
    #sys.get_neighbors(method = 'voronoi')
    sys.get_neighbors(method='cutoff', cutoff=0.9)
    sys.calculate_q([4, 6], averaged=True)
    atoms = sys.get_allatoms()
    assert np.round(atoms[0].get_q(4), decimals=2) == 0.51
    assert np.round(atoms[0].get_q(4, averaged=True), decimals=2) == 0.51
    assert np.round(atoms[0].get_q([4, 6])[0], decimals=2) == 0.51
    assert np.round(atoms[0].get_q([4, 6], averaged=True)[1],
                    decimals=2) == 0.63
    assert np.round(atoms[0].get_q([4, 6]), decimals=2)[0] == 0.51
    assert np.round(atoms[0].get_q([4, 6], averaged=True)[1],
                    decimals=2) == 0.63

    #now change the q4 values
    atoms[0].set_q(4, .23)
    atoms[0].set_q(4, .23, averaged=True)
    assert np.round(atoms[0].get_q(4), decimals=2) == 0.23
    assert np.round(atoms[0].get_q(4, averaged=True), decimals=2) == 0.23

    atoms[0].set_q([4, 6], [.23, .46])
    atoms[0].set_q([4, 6], [.23, .46], averaged=True)
    assert np.round(atoms[0].get_q(4), decimals=2) == 0.23
    assert np.round(atoms[0].get_q(4, averaged=True), decimals=2) == 0.23
    assert np.round(atoms[0].get_q(6), decimals=2) == 0.46
    assert np.round(atoms[0].get_q(6, averaged=True), decimals=2) == 0.46
Exemple #5
0
def test_q_list():
    #this might take a while, it will find all qs
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[4, 4, 4])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)
    sys.get_neighbors(method='voronoi')

    sys.calculate_q([2, 4], averaged=True)
    q = sys.get_qvals([2, 4], averaged=True)
Exemple #6
0
def test_q_8():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [4, 4, 4])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)
    sys.get_neighbors(method = 'voronoi')

    sys.calculate_q(8, averaged=True)
    q = sys.get_qvals(8, averaged=True)
    assert np.round(np.mean(np.array(q)), decimals=2) == 0.33
Exemple #7
0
def test_voro_props():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[2, 2, 2])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)

    sys.get_neighbors(method='voronoi')
    atoms = sys.get_allatoms()
    atom = atoms[0]
    v = atom.get_vorovector()
    assert v == [0, 6, 0, 8]
Exemple #8
0
def test_q_4():
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[4, 4, 4])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)
    #sys.get_neighbors(method = 'voronoi')
    sys.get_neighbors(method='cutoff', cutoff=0.9)
    sys.calculate_q(4, averaged=True)
    q = sys.get_qvals(4, averaged=True)
    assert np.round(np.mean(np.array(q)),
                    decimals=2) == 0.51, "Calculated q4 value is wrong!"
Exemple #9
0
def test_triclinic():
    sys = pc.System()
    sys.read_inputfile('tests/conf.primitive.bcc.supercell.dump')
    sys.get_neighbors(method = 'cutoff', cutoff=1.2)
    atoms = sys.get_allatoms()
    neighs = atoms[0].get_neighbors()
    assert len(neighs) == 14

    sys.get_neighbors(method = 'cutoff', cutoff=0.9)
    atoms = sys.get_allatoms()
    neighs = atoms[0].get_neighbors()
    assert len(neighs) == 8
Exemple #10
0
def test_system_atom_access():
    #create some atoms
    atoms, boxdims = pcs.make_crystal('bcc')
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)
    atom = sys.get_atom(0)
    assert atom.get_x() == [0, 0, 0]

    atom.set_x([0.1, 0.1, 0.1])
    sys.set_atom(atom)
    atom = sys.get_atom(0)
    assert atom.get_x() == [0.1, 0.1, 0.1]    
Exemple #11
0
def test_q_2():
    #this might take a while, it will find all qs
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [6, 6, 6])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)
    #sys.read_inputfile("tests/bcc.dat")
    sys.get_neighbors(method = 'voronoi')
    #sys.get_neighbors(method = 'cutoff', cutoff=0.9)

    sys.calculate_q(2)
    q = sys.get_qvals(2)
    assert np.round(np.mean(np.array(q)), decimals=2) == 0.00 
Exemple #12
0
def test_create_multislice_dump():
    """
    Create a multitest dump file and test it
    """
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[6, 6, 6])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)
    ptp.write_structure(sys, "tests/bcc1.dump")

    atoms2, boxdims2 = pcs.make_crystal('bcc', repetitions=[6, 6, 6])
    #modify the coordinates of one atom
    x = atoms2[0].get_x()
    x[0] += 0.01
    atoms2[0].set_x(x)
    #write it out
    sys2 = pc.System()
    sys2.assign_atoms(atoms2, boxdims2)
    ptp.write_structure(sys2, "tests/bcc2.dump")

    #now merge the two dump files
    os.system("cat tests/bcc1.dump tests/bcc2.dump > tests/bcc3.dat")
    os.remove("tests/bcc1.dump")
    os.remove("tests/bcc2.dump")

    #now this file should have info of both - read it in
    sys3 = pc.System()
    sys3.read_inputfile("tests/bcc3.dat", frame=1)
    atoms = sys3.get_allatoms()
    assert atoms[0].get_x() == [0.01, 0, 0]

    #now this file should have info of both - read it in
    sys4 = pc.System()
    sys4.read_inputfile("tests/bcc3.dat", frame=0)
    atoms = sys4.get_allatoms()
    assert atoms[0].get_x() == [0.0, 0, 0]

    #now cleanup
    os.remove("tests/bcc3.dat")
Exemple #13
0
def test_q_2():
    #this might take a while, it will find all qs
    atoms, boxdims = pcs.make_crystal('bcc', repetitions=[6, 6, 6])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)
    #sys.read_inputfile("tests/bcc.dat")
    sys.get_neighbors(method='voronoi')
    atoms = sys.get_allatoms()
    vols = []
    avgvols = []
    for atom in atoms:
        vols.append(atom.get_volume())
        avgvols.append(atom.get_volume(averaged=True))
    assert np.mean(np.array(vols)) == 0.5
    assert np.mean(np.array(avgvols)) == 0.5
Exemple #14
0
def test_poscar():
    sys = pc.System()
    sys.read_inputfile('tests/POSCAR', format='poscar')
    atoms = sys.get_allatoms()
    assert len(atoms) == 42

    #now assert atoms of different types
    type1 = len([atom for atom in atoms if atom.get_type() == 1])
    type2 = len([atom for atom in atoms if atom.get_type() == 2])
    type3 = len([atom for atom in atoms if atom.get_type() == 3])
    assert type1 == 38
    assert type2 == 2
    assert type3 == 2

    #now test the coorfinates of the atom
    assert sys.get_box() == [[0.0, 18.768662916], [0.0, 8.9728430088], [0.0, 2.83746]] 

    #now check coordinates of first atom
    assert atoms[0].get_x() == [0.020389021322710754, 8.8981229427339, 0.0005978263145216028]
Exemple #15
0
def test_neighbors_system():
    #create some atoms
    atoms, boxdims = pcs.make_crystal('bcc', repetitions = [6, 6, 6])
    sys = pc.System()
    sys.assign_atoms(atoms, boxdims)

    #test that atoms are set properly
    assert len(sys.get_allatoms()) == 432

    #then lets find neighbors
    #cutoff method - first shell only
    sys.get_neighbors(method = 'cutoff', cutoff=0.867)
    #any atom should have 8 neighbors
    atoms = sys.get_allatoms()
    assert atoms[0].get_coordination() == 8

    sys.reset_neighbors()

    #cutoff method - second shell
    sys.get_neighbors(method = 'cutoff', cutoff=1.1)
    #any atom should have 8 neighbors
    atoms = sys.get_allatoms()
    assert atoms[0].get_coordination() == 14

    #cutoff method - third shell
    sys.get_neighbors(method = 'cutoff', cutoff=1.5)
    #any atom should have 8 neighbors
    atoms = sys.get_allatoms()
    assert atoms[0].get_coordination() == 26

    sys.reset_neighbors()
    #voronoi method - first shell only
    sys.get_neighbors(method = 'voronoi')
    #any atom should have 8 neighbors
    atoms = sys.get_allatoms()
    assert atoms[0].get_coordination() == 14

    assert np.round(sys.get_distance(atoms[0], atoms[1]), decimals=2) == 0.87
Exemple #16
0
def test_basic_system():
    #basic system tests
    sys = pc.System()