Exemplo n.º 1
0
 def adsorb(self,
            mol,
            loc=[0.5, 0.5, 0.5],
            spec_z=False,
            theta=[0, 0, 0],
            v=[0, 0, 0],
            distance=2,
            ifpca=True,
            frac=True):
     from sklearn.decomposition import PCA
     if ifpca:
         pca = PCA(n_components=3)
         pca.fit(mol.cart_coords)
         new_coords = pca.transform(mol.cart_coords)
         newmol = Molecule(coords=new_coords, species=mol.species)
     else:
         newmol = mol
     newmol.rotate_sites(axis=[1, 0, 0], theta=theta[0] / 180 * math.pi)
     newmol.rotate_sites(axis=[0, 1, 0], theta=theta[1] / 180 * math.pi)
     newmol.rotate_sites(axis=[0, 0, 1], theta=theta[2] / 180 * math.pi)
     if not spec_z:
         if frac:
             ztop = np.max(self.poscar.structure.frac_coords[:, 2], axis=0)
             zz = ztop + distance / self.poscar.structure.lattice.c
             loc = [loc[0] + v[0], loc[1] + v[1], zz + v[2]]
         else:
             ztop = np.max(self.poscar.structure.cart_coords, axis=0)[2]
             loc[2] = distance + ztop
     else:
         loc = [loc[0] + v[0], loc[1] + v[1], loc[2] + v[2]]
     if frac:
         loc = self.f_to_c(loc)
     sufsite = AdsorbateSiteFinder(self.poscar.structure)
     ads_struct = sufsite.add_adsorbate(newmol,
                                        loc,
                                        reorient=True,
                                        translate=False)
     return ads_struct