|
1 | 1 | """This module provides classes to specify atomic structure."""
|
| 2 | + |
2 | 3 | import numpy as np
|
3 | 4 | from jarvis.core.composition import Composition
|
4 | 5 | from jarvis.core.specie import Specie, atomic_numbers_to_symbols
|
@@ -698,14 +699,23 @@ def from_dict(self, d={}):
|
698 | 699 |
|
699 | 700 | def remove_site_by_index(self, site=0):
|
700 | 701 | """Remove an atom by its index number."""
|
| 702 | + return self.remove_sites_by_indices(indices=[site]) |
| 703 | + |
| 704 | + def remove_sites_by_indices(self, indices=[0], in_place=False): |
| 705 | + """Remove multiple atoms by their corresponding indices number.""" |
701 | 706 | new_els = []
|
702 | 707 | new_coords = []
|
703 | 708 | new_props = []
|
704 | 709 | for ii, i in enumerate(self.frac_coords):
|
705 |
| - if ii != site: |
| 710 | + if ii not in indices: |
706 | 711 | new_els.append(self.elements[ii])
|
707 | 712 | new_coords.append(self.frac_coords[ii])
|
708 | 713 | new_props.append(self.props[ii])
|
| 714 | + if in_place: |
| 715 | + self.elements = new_els |
| 716 | + self.coords = new_coords |
| 717 | + self.props = new_props |
| 718 | + return self |
709 | 719 | return Atoms(
|
710 | 720 | lattice_mat=self.lattice_mat,
|
711 | 721 | elements=new_els,
|
@@ -1268,49 +1278,50 @@ def make_supercell(self, dim=[2, 2, 2]):
|
1268 | 1278 | dim = np.array(dim)
|
1269 | 1279 | if dim.shape == (3, 3):
|
1270 | 1280 | dim = np.array([int(np.linalg.norm(v)) for v in dim])
|
1271 |
| - coords = self.frac_coords |
1272 |
| - all_symbs = self.elements # [i.symbol for i in s.species] |
1273 |
| - nat = len(coords) |
1274 |
| - |
1275 |
| - new_nat = nat * dim[0] * dim[1] * dim[2] |
1276 |
| - new_coords = np.zeros((new_nat, 3)) |
1277 |
| - new_symbs = [] # np.chararray((new_nat)) |
1278 |
| - props = [] # self.props |
1279 |
| - |
1280 |
| - ct = 0 |
1281 |
| - for i in range(nat): |
1282 |
| - for j in range(dim[0]): |
1283 |
| - for k in range(dim[1]): |
1284 |
| - for m in range(dim[2]): |
1285 |
| - props.append(self.props[i]) |
1286 |
| - new_coords[ct][0] = (coords[i][0] + j) / float(dim[0]) |
1287 |
| - new_coords[ct][1] = (coords[i][1] + k) / float(dim[1]) |
1288 |
| - new_coords[ct][2] = (coords[i][2] + m) / float(dim[2]) |
1289 |
| - new_symbs.append(all_symbs[i]) |
1290 |
| - ct = ct + 1 |
1291 |
| - |
1292 |
| - nat = new_nat |
1293 |
| - |
1294 |
| - nat = len(coords) # int(s.composition.num_atoms) |
1295 |
| - lat = np.zeros((3, 3)) |
1296 |
| - box = self.lattice_mat |
1297 |
| - lat[0][0] = dim[0] * box[0][0] |
1298 |
| - lat[0][1] = dim[0] * box[0][1] |
1299 |
| - lat[0][2] = dim[0] * box[0][2] |
1300 |
| - lat[1][0] = dim[1] * box[1][0] |
1301 |
| - lat[1][1] = dim[1] * box[1][1] |
1302 |
| - lat[1][2] = dim[1] * box[1][2] |
1303 |
| - lat[2][0] = dim[2] * box[2][0] |
1304 |
| - lat[2][1] = dim[2] * box[2][1] |
1305 |
| - lat[2][2] = dim[2] * box[2][2] |
1306 |
| - super_cell = Atoms( |
1307 |
| - lattice_mat=lat, |
1308 |
| - coords=new_coords, |
1309 |
| - elements=new_symbs, |
1310 |
| - props=props, |
1311 |
| - cartesian=False, |
1312 |
| - ) |
1313 |
| - return super_cell |
| 1281 | + return self.make_supercell_matrix(dim) |
| 1282 | + # coords = self.frac_coords |
| 1283 | + # all_symbs = self.elements # [i.symbol for i in s.species] |
| 1284 | + # nat = len(coords) |
| 1285 | + |
| 1286 | + # new_nat = nat * dim[0] * dim[1] * dim[2] |
| 1287 | + # new_coords = np.zeros((new_nat, 3)) |
| 1288 | + # new_symbs = [] # np.chararray((new_nat)) |
| 1289 | + # props = [] # self.props |
| 1290 | + |
| 1291 | + # ct = 0 |
| 1292 | + # for i in range(nat): |
| 1293 | + # for j in range(dim[0]): |
| 1294 | + # for k in range(dim[1]): |
| 1295 | + # for m in range(dim[2]): |
| 1296 | + # props.append(self.props[i]) |
| 1297 | + # new_coords[ct][0] = (coords[i][0] + j) / float(dim[0]) |
| 1298 | + # new_coords[ct][1] = (coords[i][1] + k) / float(dim[1]) |
| 1299 | + # new_coords[ct][2] = (coords[i][2] + m) / float(dim[2]) |
| 1300 | + # new_symbs.append(all_symbs[i]) |
| 1301 | + # ct = ct + 1 |
| 1302 | + |
| 1303 | + # nat = new_nat |
| 1304 | + |
| 1305 | + # nat = len(coords) # int(s.composition.num_atoms) |
| 1306 | + # lat = np.zeros((3, 3)) |
| 1307 | + # box = self.lattice_mat |
| 1308 | + # lat[0][0] = dim[0] * box[0][0] |
| 1309 | + # lat[0][1] = dim[0] * box[0][1] |
| 1310 | + # lat[0][2] = dim[0] * box[0][2] |
| 1311 | + # lat[1][0] = dim[1] * box[1][0] |
| 1312 | + # lat[1][1] = dim[1] * box[1][1] |
| 1313 | + # lat[1][2] = dim[1] * box[1][2] |
| 1314 | + # lat[2][0] = dim[2] * box[2][0] |
| 1315 | + # lat[2][1] = dim[2] * box[2][1] |
| 1316 | + # lat[2][2] = dim[2] * box[2][2] |
| 1317 | + # super_cell = Atoms( |
| 1318 | + # lattice_mat=lat, |
| 1319 | + # coords=new_coords, |
| 1320 | + # elements=new_symbs, |
| 1321 | + # props=props, |
| 1322 | + # cartesian=False, |
| 1323 | + # ) |
| 1324 | + # return super_cell |
1314 | 1325 |
|
1315 | 1326 | def get_lll_reduced_structure(self):
|
1316 | 1327 | """Get LLL algorithm based reduced structure."""
|
@@ -1431,6 +1442,17 @@ def get_string(self, cart=True, sort_order="X"):
|
1431 | 1442 | result = header + middle + rest
|
1432 | 1443 | return result
|
1433 | 1444 |
|
| 1445 | + def clone(self): |
| 1446 | + """Clones the class instance.""" |
| 1447 | + return Atoms( |
| 1448 | + lattice_mat=self.lattice_mat, |
| 1449 | + elements=self.elements, |
| 1450 | + coords=self.frac_coords, |
| 1451 | + props=self.props, |
| 1452 | + cartesian=self.cartesian, |
| 1453 | + show_props=self.show_props, |
| 1454 | + ) |
| 1455 | + |
1434 | 1456 |
|
1435 | 1457 | class VacuumPadding(object):
|
1436 | 1458 | """Adds vaccum padding to make 2D structure or making molecules."""
|
@@ -1860,18 +1882,18 @@ def to_optimade(
|
1860 | 1882 | info_at["cartesian_site_positions"] = atoms.cart_coords[order].tolist()
|
1861 | 1883 | info_at["nperiodic_dimensions"] = 3
|
1862 | 1884 | # info_at["species"] = atoms.elements
|
1863 |
| - info_at[ |
1864 |
| - "species" |
1865 |
| - ] = self.get_optimade_species() # dict(atoms.composition.to_dict()) |
| 1885 | + info_at["species"] = ( |
| 1886 | + self.get_optimade_species() |
| 1887 | + ) # dict(atoms.composition.to_dict()) |
1866 | 1888 | info_at["elements_ratios"] = list(
|
1867 | 1889 | atoms.composition.atomic_fraction.values()
|
1868 | 1890 | )
|
1869 | 1891 | info_at["structure_features"] = []
|
1870 | 1892 | info_at["last_modified"] = str(now)
|
1871 | 1893 | # info_at["more_data_available"] = True
|
1872 |
| - info_at[ |
1873 |
| - "chemical_formula_descriptive" |
1874 |
| - ] = atoms.composition.reduced_formula |
| 1894 | + info_at["chemical_formula_descriptive"] = ( |
| 1895 | + atoms.composition.reduced_formula |
| 1896 | + ) |
1875 | 1897 | info_at["dimension_types"] = [1, 1, 1]
|
1876 | 1898 | info["attributes"] = info_at
|
1877 | 1899 | return info
|
|
0 commit comments