def test_one(): Z, symbol = get_atomic_number_symbol(Z=8) assert Z[0] == 8 assert symbol[0] == 'O' Z, symbol = get_atomic_number_symbol(symbol='C') assert Z[0] == 6 assert symbol[0] == 'C' Z, symbol = get_atomic_number_symbol(Z=10, symbol='Ne') assert Z[0] == 10 assert symbol[0] == 'Ne'
def test_array(): Z, symbol = get_atomic_number_symbol(Z=[6, 7, 8]) assert_array_equal(Z, [6, 7, 8]) assert_array_equal(symbol, ['C', 'N', 'O']) Z, symbol = get_atomic_number_symbol(symbol=['Au', 'Ag']) assert_array_equal(Z, [79, 47]) assert_array_equal(symbol, ['Au', 'Ag']) Z, symbol = get_atomic_number_symbol(Z=[1, 2, 3], symbol=['B', 'C', 'F']) assert_array_equal(Z, [5, 6, 9]) assert_array_equal(symbol, ['B', 'C', 'F'])
def repeat(self, rep): """Repeat the cells a number of time along each dimension *rep* argument should be either three value like *(1,2,3)* or a single value *r* equivalent to *(r,r,r)*.""" if isinstance(rep, int): rep = np.array((rep, rep, rep, 1)) else: rep = np.append(rep, 1) ncells = np.array(self.atoms.index.max()) + 1 x = np.tile(np.reshape(self.x, ncells), rep).flatten() y = np.tile(np.reshape(self.y, ncells), rep).flatten() z = np.tile(np.reshape(self.z, ncells), rep).flatten() Z = np.tile(np.reshape(self.get_atomic_numbers(), ncells), rep).flatten() miindex = get_miindex(0, ncells * rep) self.atoms = DataFrame(index=miindex, columns=['Z', 'symbol', 'x', 'y', 'z']) self.atoms.Z, self.atoms.symbol = get_atomic_number_symbol(Z=Z) self.atoms.x = x self.atoms.y = y self.atoms.z = z
def repeat(self, rep): """Repeat the cells a number of time along each dimension *rep* argument should be either three value like *(1,2,3)* or a single value *r* equivalent to *(r,r,r)*.""" if isinstance(rep, int): rep = np.array((rep, rep, rep, 1)) else: rep = np.append(rep, 1) ncells = np.array(self.atoms.index.max()) + 1 x = np.tile(np.reshape(self.x, ncells), rep).flatten() y = np.tile(np.reshape(self.y, ncells), rep).flatten() z = np.tile(np.reshape(self.z, ncells), rep).flatten() Z = np.tile(np.reshape(self.get_atomic_numbers(), ncells), rep).flatten() miindex = get_miindex(0, ncells * rep) self.atoms = DataFrame(index=miindex, columns=[ 'Z', 'symbol', 'x', 'y', 'z', 'cartn_x', 'cartn_y', 'cartn_z' ]) self.atoms.Z, self.atoms.symbol = get_atomic_number_symbol(Z=Z) self.atoms.x = x self.atoms.y = y self.atoms.z = z self._recalculate_cartn()
def __get_atomic_numbers(self): """Wrapper to get the atomic numbers from different structure classes""" from javelin.utils import get_atomic_number_symbol try: # ASE structure return self.structure.get_atomic_numbers() except AttributeError: try: # diffpy structure atomic_numbers, _ = get_atomic_number_symbol( symbol=self.structure.element) return atomic_numbers except AttributeError: raise ValueError("Unable to get elements from structure")
def add_atom(self, i=0, j=0, k=0, site=0, Z=None, symbol=None, position=None): Z, symbol = get_atomic_number_symbol([Z], [symbol]) if position is None: raise ValueError("position not provided") self.atoms.loc[i, j, k, site] = [Z[0], symbol[0], position[0], position[1], position[2]] if self.rotations is not None: self.rotations[i, j, k] = [1, 0, 0, 0] if self.translations is not None: self.translations[i, j, k] = [0, 0, 0]
def test_raises(): with pytest.raises(ValueError): get_atomic_number_symbol() with pytest.raises(ValueError): get_atomic_number_symbol(symbol='A') with pytest.raises(KeyError): get_atomic_number_symbol(Z=1000)
def __init__(self, symbols=None, numbers=None, unitcell=1, ncells=None, positions=None, rotations=False, translations=False, magnetic_moments=False): if positions is not None: numberOfAtoms = len(positions) else: numberOfAtoms = 0 if ncells is not None: ncells = np.asarray(ncells) if ncells is not None and positions is not None and ncells.prod() != numberOfAtoms: raise ValueError("Product of ncells values doesn't equal length of positions") if isinstance(unitcell, UnitCell): self.unitcell = unitcell else: self.unitcell = UnitCell(unitcell) miindex = get_miindex(numberOfAtoms, ncells) self.atoms = DataFrame(index=miindex, columns=['Z', 'symbol', 'x', 'y', 'z']) if numbers is not None or symbols is not None: self.atoms.Z, self.atoms.symbol = get_atomic_number_symbol(Z=numbers, symbol=symbols) positions = np.asarray(positions) self.atoms[['x', 'y', 'z']] = positions if rotations: self.rotations = DataFrame(index=miindex.droplevel(3), columns=['w', 'x', 'y', 'z']) else: self.rotations = None if translations: self.translations = DataFrame(index=miindex.droplevel(3), columns=['x', 'y', 'z']) else: self.translations = None if magnetic_moments: self.magmons = DataFrame(index=miindex, columns=['spinx', 'spiny', 'spinz']) else: self.magmons = None
def add_atom(self, i=0, j=0, k=0, site=0, Z=None, symbol=None, position=None): Z, symbol = get_atomic_number_symbol([Z], [symbol]) if position is None: raise ValueError("position not provided") cartn = self.unitcell.cartesian(position)[0] self.atoms.loc[i, j, k, site] = [ Z[0], symbol[0], position[0], position[1], position[2], cartn[0], cartn[1], cartn[2] ] if self.rotations is not None: self.rotations[i, j, k] = [1, 0, 0, 0] if self.translations is not None: self.translations[i, j, k] = [0, 0, 0]
def __init__(self, symbols=None, numbers=None, unitcell=1, ncells=None, positions=None, rotations=False, translations=False, magnetic_moments=False): if positions is not None: numberOfAtoms = len(positions) else: numberOfAtoms = 0 if ncells is not None: ncells = np.asarray(ncells) if ncells is not None and positions is not None and ncells.prod( ) != numberOfAtoms: raise ValueError( "Product of ncells values doesn't equal length of positions") if isinstance(unitcell, UnitCell): self.unitcell = unitcell else: self.unitcell = UnitCell(unitcell) miindex = get_miindex(numberOfAtoms, ncells) self.atoms = DataFrame(index=miindex, columns=[ 'Z', 'symbol', 'x', 'y', 'z', 'cartn_x', 'cartn_y', 'cartn_z' ]) if numbers is not None or symbols is not None: self.atoms.Z, self.atoms.symbol = get_atomic_number_symbol( Z=numbers, symbol=symbols) positions = np.asarray(positions) self.atoms[['x', 'y', 'z']] = positions if rotations: self.rotations = DataFrame(index=miindex.droplevel(3), columns=['w', 'x', 'y', 'z']) else: self.rotations = None if translations: self.translations = DataFrame(index=miindex.droplevel(3), columns=['x', 'y', 'z']) else: self.translations = None if magnetic_moments: self.magmons = DataFrame(index=miindex, columns=['spinx', 'spiny', 'spinz']) else: self.magmons = None self._recalculate_cartn()