Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def heavy(self):
fs = [
self.ssf.from_preset("CrystalNNFingerprint_ops"),
sf.ChemicalOrdering(),
sf.StructuralHeterogeneity(),
sf.MaximumPackingEfficiency(),
sf.XRDPowderPattern(),
sf.Dimensionality(),
sf.OrbitalFieldMatrix(flatten=True),
sf.JarvisCFID(),
]
fs += self.express
fs = self._add_external(fs)
return self._get_featurizers(fs)
def transform(self, df, y=None):
# iterate through dataframe rows
for i, rows in df.iterrows():
f = Poscar.from_file(df.at[i, self.structure_col])
structure = f.structure # create pymatgen structure object
df.at[i, self.structure_col] = structure # replace path with structure object
# iterate through structural_features list
for struc_feat in range(len(self.structural_features)):
# nested loop to check structural_features list item against matminer structures list
for feature_name in inspect.getmembers(struc, inspect.isclass):
# if structural feature item is a match
if feature_name[0] == self.structural_features[struc_feat]:
sf = getattr(struc, self.structural_features[struc_feat])() # instantiates the structure featurizer
df = sf.fit_featurize_dataframe(df, self.structure_col) # fit_featurize_dataframe() works for all
# updates dataframe if the structural feature happens to be the GlobalSymmetryFeatures
if self.structural_features[struc_feat] == "GlobalSymmetryFeatures":
df = df.drop('crystal_system', axis=1)
for i, rows in df.iterrows():
if df.at[i, "is_centrosymmetric"] == True:
df.at[i, "is_centrosymmetric"] = 1
elif df.at[i, "is_centrosymmetric"] == False:
df.at[i, "is_centrosymmetric"] = 0
break # structure feature was found for this iteration, repeat
# drop unused dataframe columns for rest of application
df = df.drop(self.structure_col, axis=1)
df = df.drop('Material', axis=1)
return df # return generated dataframe
def __init__(self, exclude=None):
super(StructureFeaturizers, self).__init__(exclude=exclude)
self.ssf = sf.SiteStatsFingerprint
def transform(self, df, y=None):
# iterate through dataframe rows
for i, rows in df.iterrows():
f = Poscar.from_file(df.at[i, self.structure_col])
structure = f.structure # create pymatgen structure object
df.at[i, self.structure_col] = structure # replace path with structure object
# iterate through structural_features list
for struc_feat in range(len(self.structural_features)):
# nested loop to check structural_features list item against matminer structures list
for feature_name in inspect.getmembers(struc, inspect.isclass):
# if structural feature item is a match
if feature_name[0] == self.structural_features[struc_feat]:
sf = getattr(struc, self.structural_features[struc_feat])() # instantiates the structure featurizer
df = sf.fit_featurize_dataframe(df, self.structure_col) # fit_featurize_dataframe() works for all
# updates dataframe if the structural feature happens to be the GlobalSymmetryFeatures
if self.structural_features[struc_feat] == "GlobalSymmetryFeatures":
df = df.drop('crystal_system', axis=1)
for i, rows in df.iterrows():
if df.at[i, "is_centrosymmetric"] == True:
df.at[i, "is_centrosymmetric"] = 1
elif df.at[i, "is_centrosymmetric"] == False:
df.at[i, "is_centrosymmetric"] = 0
break # structure feature was found for this iteration, repeat
# drop unused dataframe columns for rest of application
df = df.drop(self.structure_col, axis=1)
def _add_external(self, fset):
# Prevent import errors
require_external = []
if torch and cgcnn:
require_external.append(sf.CGCNNFeaturizer())
if dscribe:
require_external.append(sf.SOAP())
return fset + require_external