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_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_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
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_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