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
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
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
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)
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
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]
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!"
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]
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
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
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")
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