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__delitem__(self):
cell = np.eye(3) * 10.0
basis_0 = Atoms(["O"], scaled_positions=[[0.5, 0.5, 0.5]], cell=cell)
basis_1 = Atoms(["H"], scaled_positions=[[0.75, 0.75, 0.75]], cell=cell)
basis_2 = Atoms(["H"], scaled_positions=[[0.25, 0.25, 0.25]], cell=cell)
basis_3 = Atoms(
["H", "O", "N"],
scaled_positions=[[0.35, 0.35, 0.35], [0.0, 0.0, 0.0], [0.0, 0.0, 0.1]],
cell=cell,
)
pse = PeriodicTable()
pse.add_element("O", "O_up", spin="up")
o_up = pse.element("O_up")
basis_4 = Atoms([o_up], scaled_positions=[[0.27, 0.27, 0.27]], cell=cell)
b = basis_0 + basis_1 + basis_2 + basis_3 + basis_4
O_indices = b.select_index("O")
self.assertEqual(len(b), 7)
self.assertEqual(len(b.indices), 7)
self.assertEqual(len(b.species), 4)
b.__delitem__(O_indices[0])
self.assertEqual(b.get_chemical_formula(), "H3NOO_up")
self.assertEqual(len(b), 6)
self.assertEqual(len(b.indices), 6)
self.assertEqual(len(b._tag_list), 6)
self.assertEqual(len(b.species), 4)
O_indices = b.select_index("O")
b.__delitem__(O_indices)
self.assertEqual(len(basis.get_species_symbols()), 2)
basis = self.CO2.copy()
basis[[0]] = "N"
self.assertEqual(basis.get_chemical_formula(), "NO2")
self.assertEqual(len(basis.species), 2)
self.assertEqual(len(basis.get_species_symbols()), 2)
basis[[0]] = "O"
self.assertEqual(basis.get_chemical_formula(), "O3")
self.assertEqual(len(basis.species), 1)
self.assertEqual(len(basis.get_species_symbols()), 1)
basis[[0, 2]] = "H"
self.assertEqual(basis.get_chemical_formula(), "H2O")
self.assertEqual(len(basis.species), 2)
self.assertEqual(len(basis.get_species_symbols()), 2)
pse = PeriodicTable()
pse.add_element("O", "O_up", spin="up")
o_up = pse.element("O_up")
basis[[0, 2]] = o_up
self.assertEqual(basis.get_chemical_formula(), "OO_up2")
self.assertEqual(len(basis.species), 2)
self.assertEqual(len(basis.get_species_symbols()), 2)
basis[0:3] = "N"
self.assertEqual(basis.get_chemical_formula(), "N3")
self.assertEqual(len(basis.species), 1)
self.assertEqual(len(basis.get_species_symbols()), 1)
basis[:] = "Ne"
self.assertEqual(basis.get_chemical_formula(), "Ne3")
self.assertEqual(len(basis.species), 1)
self.assertEqual(len(basis.get_species_symbols()), 1)
basis[-2:] = "H"
self.assertEqual(basis.get_chemical_formula(), "H2Ne")
def test_get_chemical_symbols(self):
self.assertTrue(
np.array_equal(self.CO2.get_chemical_symbols(), ["C", "O", "O"])
)
cell = np.eye(3) * 10.0
pse = PeriodicTable()
pse.add_element("O", "O_up", spin="up")
o_up = pse.element("O_up")
basis = Atoms([o_up], scaled_positions=[[0.27, 0.27, 0.27]], cell=cell)
self.assertTrue(np.array_equal(basis.get_chemical_symbols(), ["O_up"]))
def setUpClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
cls.project = Project(os.path.join(cls.file_location, "../static/sphinx"))
pt = PeriodicTable()
pt.add_element(parent_element="Fe", new_element="Fe_up", spin="0.5")
Fe_up = pt.element("Fe_up")
cls.basis = Atoms(
elements=[Fe_up, Fe_up],
scaled_positions=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]],
cell=2.6 * np.eye(3),
)
cls.sphinx = cls.project.create_job("Sphinx", "job_sphinx")
cls.sphinx_band_structure = cls.project.create_job("Sphinx", "sphinx_test_bs")
cls.sphinx_2_3 = cls.project.create_job("Sphinx", "sphinx_test_2_3")
cls.sphinx_2_5 = cls.project.create_job("Sphinx", "sphinx_test_2_5")
cls.sphinx_aborted = cls.project.create_job("Sphinx", "sphinx_test_aborted")
cls.sphinx.structure = cls.basis
cls.sphinx.fix_spin_constraint = True
cls.sphinx_band_structure.structure = cls.project.create_structure("Fe", "bcc", 2.81)
cls.sphinx_band_structure.structure = cls.sphinx_band_structure.structure.create_line_mode_structure()
def test_create_Fe_bcc(self):
self.pse = PeriodicTable()
self.pse.add_element("Fe", "Fe_up", spin="up", pseudo_name="GGA")
self.pse.add_element("Fe", "Fe_down", spin="down", pseudo_name="GGA")
Fe_up = self.pse.element("Fe_up")
Fe_down = self.pse.element("Fe_down")
self.Fe_bcc = Atoms(
[Fe_up, Fe_down],
scaled_positions=[[0, 0, 0], [0.25, 0.25, 0.25]],
cell=np.identity(3),
)
self.Fe_bcc.add_tag("group")
self.Fe_bcc.group[:] = 0
Returns:
pyiron.objects.structure.atoms.Atoms instance
"""
file_string = []
with open(filename) as f:
for line in f:
line = line.strip()
file_string.append(line)
cell_trigger = "cell"
cell_string = list()
species_list = list()
species_trigger = "element"
positions_dict = OrderedDict()
positions = list()
pse = PeriodicTable()
for i, line in enumerate(file_string):
if cell_trigger in line:
for j in range(len(file_string)):
line_str = file_string[i + j]
cell_string.append(line_str)
if ";" in line_str:
break
if species_trigger in line:
species = (
line.strip().split("=")[-1].replace(";", "").replace('"', "").strip()
)
species_list.append(pse.element(species))
positions_dict[species] = 0
for j in range(len(file_string) - i):
line_str = file_string[i + j]
k = 0
if not (node.tag == "atominfo"):
raise AssertionError()
species_dict = OrderedDict()
for leaf in node:
if leaf.tag == "atoms":
d["n_atoms"] = self._parse_vector(leaf)[0]
if leaf.tag == "types":
d["n_species"] = self._parse_vector(leaf)[0]
if leaf.tag == "array":
if leaf.attrib["name"] == "atomtypes":
for item in leaf:
if item.tag == "set":
for sp in item:
elements = sp
if elements[1].text in species_dict.keys():
pse = PeriodicTable()
count = 1
not_unique = True
species_key = None
while not_unique:
species_key = "_".join(
[elements[1].text, str(count)]
)
if species_key not in species_dict.keys():
not_unique = False
else:
count += 1
if species_key is not None:
pse.add_element(clean_character(elements[1].text), species_key)
special_element = pse.element(species_key)
species_dict[special_element] = dict()
species_dict[special_element]["n_atoms"] = int(elements[0].text)
else:
if key.start is not None:
if key.stop is not None:
key = np.arange(key.start, key.stop, key.step)
else:
if key.start >= 0:
key = np.arange(key.start, len(self), key.step)
else:
key = np.arange(len(self) + key.start, len(self), key.step)
else:
if key.stop is not None:
key = np.arange(0, key.stop, key.step)
else:
key = np.arange(0, len(self), key.step)
if isinstance(value, (str, np.str, np.str_, int, np.int, np.int32)):
el = PeriodicTable().element(value)
elif isinstance(value, ChemicalElement):
el = value
else:
raise ValueError("The value assigned should be a string, integer or a ChemicalElement instance")
replace_list = list()
new_species = list(np.array(self.species).copy())
for sp in self.species:
replace_list.append(np.array_equal(np.sort(self.select_index(sp)),
np.sort(np.intersect1d(self.select_index(sp), key))))
if el.Abbreviation not in [spec.Abbreviation for spec in new_species]:
if not any(replace_list):
new_species.append(el)
self.set_species(new_species)
self.indices[key] = len(new_species) - 1
else:
replace_ind = np.where(replace_list)[0][0]
def inspect_periodic_table():
return PeriodicTable()
or celldisp is not None or constraint is not None or calculator is not None or info is not None:
s.logger.debug('Not supported parameter used!')
self._store_elements = dict()
self._species_to_index_dict = None
self.colorLut = ElementColorDictionary().to_lut()
self._is_scaled = False
if cell is not None:
# make it ASE compatible
if np.linalg.matrix_rank(cell) == 1:
cell = np.eye(len(cell)) * cell
else:
cell = np.array(cell)
self._cell = cell
self._species = list()
self._internal_positions = None
self._pse = PeriodicTable()
self._tag_list = SparseArray()
self.indices = np.array([])
self._info = dict()
self.arrays = dict()
self.adsorbate_info = {}
self.bonds = None
self._pbc = False
self.dimension = 3 # Default
self.units = {"length": "A", "mass": "u"}
el_index_lst = list()
element_list = None
if (elements is None) and (numbers is None) and (indices is None):
return
if numbers is not None: # for ASE compatibility