Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_analyse_ovito_centro_symmetry(self):
basis = Atoms(
"FeFe", scaled_positions=[(0, 0, 0), (0.5, 0.5, 0.5)], cell=np.identity(3)
)
self.assertTrue(
all(basis.analyse_ovito_centro_symmetry() == np.array([0.75, 0.75]))
)
def test_get_final_structure(self):
for vp in self.vp_list:
basis = vp.get_final_structure()
self.assertIsInstance(basis, Atoms)
self.assertTrue(np.max(basis.get_scaled_positions()) < 1.01)
self.assertFalse(np.max(basis.positions) < 1.01)
def test_get_majority_species(self):
basis = Atoms(
symbols=4 * ["Fe"], positions=np.random.random((4, 3)), cell=np.eye(3)
)
self.assertEqual(basis.get_majority_species()["count"], 4)
self.assertEqual(basis.get_majority_species()["symbol"], "Fe")
basis = Atoms(
symbols=["Fe", "Cu", "Ni", "Al"],
positions=np.random.random((4, 3)),
cell=np.eye(3),
)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
basis.get_majority_species()
self.assertEqual(len(w), 1)
def test_new_array(self):
pos, cell = generate_fcc_lattice()
basis = Atoms(symbols="Al", positions=pos, cell=cell)
basis.set_repeat([10, 10, 10])
spins = np.ones(len(basis))
basis.new_array(name="spins", a=spins)
self.assertTrue(np.array_equal(basis.arrays["spins"], spins))
el_list = np.array(atoms_dict["first_line"].split()[i])
el_list = np.tile(el_list, atoms_dict["species_dict"][sp_key]["count"])
symbol += atoms_dict["first_line"].split()[i]
symbol += str(atoms_dict["species_dict"][sp_key]["count"])
elif species_list is None:
raise ValueError(
"Species list should be provided since pyiron can't detect species information"
)
elements.append(el_list)
elements_new = list()
for ele in elements:
for e in ele:
elements_new.append(e)
elements = elements_new
if is_absolute:
atoms = Atoms(elements, positions=positions, cell=cell)
else:
atoms = Atoms(elements, scaled_positions=positions, cell=cell)
return atoms
def from_hdf_old(self, hdf, group_name="electronic_structure"):
"""
Retrieve the object from the hdf5 file
Args:
hdf: Path to the hdf5 file/group in the file
group_name: Name of the group under which the attributes are stored
"""
with hdf.open(group_name) as h_es:
if "structure" in h_es.list_nodes():
self.structure = Atoms().from_hdf(h_es)
nodes = h_es.list_nodes()
self.kpoint_list = h_es["k_points"]
self.kpoint_weights = h_es["k_point_weights"]
self.eigenvalue_matrix = h_es["eigenvalue_matrix"]
self.occupancy_matrix = h_es["occupancy_matrix"]
try:
self.dos_energies = h_es["dos_energies"]
self.dos_densities = h_es["dos_densities"]
self.dos_idensities = h_es["dos_idensities"]
except ValueError:
pass
if "fermi_level" in nodes:
self.efermi = h_es["fermi_level"]
if "grand_dos_matrix" in nodes:
self.grand_dos_matrix = h_es["grand_dos_matrix"]
if "resolved_densities" in nodes:
def phonopy_to_atoms(ph_atoms):
"""
Convert Phonopy Atoms to ASE-like Atoms
Args:
ph_atoms: Phonopy Atoms object
Returns: ASE-like Atoms object
"""
return Atoms(symbols=list(ph_atoms.get_chemical_symbols()),
positions=list(ph_atoms.get_positions()),
cell=list(ph_atoms.get_cell()))
def load_chk(self, fn):
'''
Load the atom types, atom type ids and structure by reading a .chk file.
**Arguments**
fn the path to the chk file
'''
system = System.from_file(fn)
system.set_standard_masses()
if len(system.pos.shape)!=2:
raise IOError("Something went wrong, positions in CHK file %s should have Nx3 dimensions" %fn)
if system.cell.rvecs is not None and len(system.cell.rvecs)>0:
self.structure = Atoms(
positions=system.pos.copy()/angstrom,
numbers=system.numbers,
masses=system.masses,
cell=system.cell.rvecs/angstrom,
)
else:
self.structure = Atoms(
positions=system.pos.copy()/angstrom,
numbers=system.numbers,
masses=system.masses,
)
if system.ffatypes is not None:
self.ffatypes = system.ffatypes
if system.ffatype_ids is not None:
self.ffatype_ids = system.ffatype_ids
def get_atom_structure(self, rel=True):
"""
Args:
rel:
Returns:
"""
# print self.relCoords, self.amat
return Atoms(
elementList=self.ElementList,
coordinates=self.coordinates,
amat=self.amat,
tag="Crystal",
rel=rel, # self.relCoords, #rel, # true or false # coordinates are given in relative lattice units
pbc=[True, True, True][0:self.dimension],
Crystal=self.crystalParamsDict
)
select = self.__select_slice(0, i0, dist) & self.__select_slice(1, i1, dist) & \
self.__select_slice(2, i2, dist)
if np.linalg.norm(r_vec) > 0:
if len(select) > 0:
sel_coordinates = rel_coordinates[select] + r_vec
new_coordinates = np.append(new_coordinates, sel_coordinates, axis=0)
if len(sel_coordinates) > 0:
# rVecs = np.array(len(sel_coordinates) * [r_vec_abs])
# pbcVec = np.append(pbcVec, rVecs, axis=0)
ia_list = np.append(ia_list, index[select])
# print "rVec: ", i0,i1,i2,rVecs[0],index[select],select
element_list = [self.indices[ia] for ia in ia_list[1:]]
self._ia_bounds = ia_list[1:]
# self._pbcVec = pbcVec[1:]
return Atoms(indices=element_list, scaled_positions=new_coordinates[1:], cell=self.cell,
dimension=len(cell), species=self.species)