def test_get_permutations(self): pos = numpy.array([ 0.5288, 0.1610, 0.9359, 0.0000, 0.0000, 0.0000, 0.2051, 0.8240, -0.6786, 0.3345, -0.9314, -0.4496, -1.0685, -0.0537, 0.1921 ]).reshape((-1, 3)) atoms = ['H', 'C', 'H', 'H', 'H'] methane = Molecule(pos, atoms) symprec = 1e-2 perm = methane.get_symmetry_permutation(symprec) num_sym = numpy.shape(perm)[0] # methane have 12 symmetry operation expected_num_sym = 12 self.assertEqual(num_sym, expected_num_sym)
def setUp(self): self.string = '''2 H1He1 H 0.000000 0.000000 0.000000 He 0.250000 0.250000 0.250000 ''' positions = [0., 0., 0., 0.25, 0.25, 0.25] atoms = ['H', 'He'] self.mol = Molecule(positions, atoms)
def test_write_string(self): wanted = '''1 H1 H 0.000000 0.000000 0.000000 ''' positions = [0., 0., 0., 2.5, 2.5, 2.5] atoms = ['H', 'Vacc'] mol = Molecule(positions, atoms) got = _write_string(mol, long_format=False) self.assertEqual(got, wanted)
def get_perms(cell,str_type='crystal',symprec=1e-3): latt = cell.lattice pos = cell.positions pos = np.dot(pos,latt) if str_type == "crystal": symm = cell.get_symmetry() trans,rots = symm['translations'],symm['rotations'] perms = np.zeros((np.shape(trans)[0],len(cell.atoms))) origin_positions = refine_positions(cell.positions) for ix, rot in enumerate(rots): for iy,o_pos in enumerate(origin_positions): new_pos = np.dot(rot,o_pos.T) + trans[ix] new_pos = np.mod(new_pos,1) new_pos = refine_positions(new_pos) idx = np.argmin(np.linalg.norm(new_pos-origin_positions,axis=1)) perms[ix,iy] = idx perms_table = np.unique(perms,axis=0) else: mol = Molecule(pos,cell.atoms) perms_table = mol.get_symmetry_permutation(symprec) return perms_table
def test_get_configurations_square_alloy(self): positions = numpy.array([ 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 2.0, 0.0, 0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 2.0, 0.0, 2.0, 2.0, 2.0, 0.0, 2.0, 2.0, 2.0 ]).reshape((-1, 3)) atoms = ['C'] * 8 molecule = Molecule(positions, atoms) cg = ConfigurationGenerator(molecule, symprec=0.05) e_num = (6, 2) sites = [(5, 6)] * 8 all_type = cg.get_configurations(sites, e_num) num_confs = len([i for i in all_type]) self.assertEqual(num_confs, 3)
def test_check(self): # c-c键和c-o键均距离不大于0.1A cco_pos = [2.0, 0.0, 0.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] cco_atoms = [6, 6, 8] mol = Molecule(cco_pos, cco_atoms) self.assertTrue(mol.check(elements=None, limit=0.1)) # 测试元素c-c距离过近, 但只测o元素时候不会过近 cco_pos = [2.0, 0.0, 0.0, 2.01, 0.0, 0.0, 0.0, 0.0, 0.0] cco_atoms = [6, 6, 8] mol = Molecule(cco_pos, cco_atoms) self.assertFalse(mol.check(elements=['C'], limit=0.1)) self.assertTrue(mol.check(elements=['O'], limit=0.1))
def get_configurations(self, sites, e_num): ''' get_configurations output specific molecule for specific concentration. parameters: sites: list of (lists or tuples), represent element disorder of each sites e_num: tuple, number of atoms in disorderd sites. yield: a tuple tuple[0]: Cell object, a list of non-redundant configurations of certain volume supercell. tuple[1]: int object, degeneracy of the configuration in all configurations of this volume. ''' perms = self.perms mol_positions = self.mol.positions for pa, d in remove_redundant(mol_positions, sites, perms, e_num=e_num): m = Molecule(pa[0], pa[1]) yield (m, d)
def _read_string(data): """ _read_string make io easy to be tested. parameter: string of xyz input return: Molecule object """ lines = [l for l in data.split('\n') if l.rstrip()] total_atoms = int(lines[0]) comment = lines[1] positions = [] atoms = [] for i in range(2, 2 + total_atoms): s = lines[i].split() atoms.append(s[0]) vec = float(s[1]), float(s[2]), float(s[3]) positions.append(vec) return Molecule(positions, atoms)
def get_mole_point_defect(self, symprec=1e-3, doped_out='all', doped_in=['Vac'], num=[1]): pos, lat, atoms = self.positions, self.lattice, self.atoms mole = Molecule(np.dot(pos, lat), atoms) cg = mole_CG(mole, symprec) sites = _get_sites(list(mole.atoms), doped_out=doped_out, doped_in=doped_in) if num == None: confs = cg.get_configurations(sites, e_num=None) comment = ["-".join(doped_in) + "-all_concentration"] else: purity_atom_num = sum( [1 if len(site) > 1 else 0 for site in sites]) confs = cg.get_configurations(sites, e_num=[purity_atom_num - sum(num)] + num) comment = list(chain(*zip(doped_in, [str(i) for i in num]))) folder = '-'.join(doped_out) + '-' + '-'.join(comment) + '-defect' if not os.path.exists('./' + folder): os.mkdir('./' + folder) else: rmtree('./' + folder) os.mkdir('./' + folder) deg = [] idx = 0 for c, _deg in confs: c.lattice = lat c._positions = np.dot(c.positions, np.linalg.inv(lat)) write_poscar(c, folder, idx) deg.append(_deg) idx += 1 np.savetxt(os.path.join(folder, "deg.txt"), deg, fmt='%d')
def setUp(self): molecule = Molecule(positions_c60, atoms_c60) self.cg = ConfigurationGenerator(molecule, symprec=0.05)
def test_init(self): positions = [0, 0, 0] atoms = ['NaN_10'] mole = Molecule(positions, atoms) self.assertEqual(mole.atoms.tolist(), [1010])