How to use CrystalNNFingerprint

Dear there

Could someone show me am example about how to use CrystalNNFingerprint?

Thank you very much!

Best Wishes

Hi,

CrystalNNFingerprint is a site featurizer which requires both a structure and a site index to featurize. If you want to featurize a single site, you can use:

from matminer.datasets.convenience_loaders import load_elastic_tensor
from matminer.featurizers.site import CrystalNNFingerprint

# loads dataset as a pandas DataFrame object
df = load_elastic_tensor() 

# get a single structure from the dataset
structure = df.iloc[0]["structure"] 

# initialize the featurizer to use structural order parameters (i.e., 
# octahedral, tetrahedral) rather than coordination number.
cnnf = CrystalNNFingerprint.from_preset("ops")

# get the features for the first site in the structure.
site_1_features = cnnf.featurize(structure, 0)

# get the feature labels
print(cnnf.feature_labels())

The fingerprint for a whole structure can be obtained using SiteStatsFeaturizer. This can be used in a similar way to all structural featurizers. They can be run on either:

  • A pandas DataFrame containing multiple Structure objects.
  • A single Structure object.

For example, to run the featurizer on a DataFrame containing multiple Structure objects:

from matminer.datasets.convenience_loaders import load_elastic_tensor
from matminer.featurizers.structure import SiteStatsFingerprint

df = load_elastic_tensor()  # loads dataset in a pandas DataFrame object

# initialize SiteStatsFingerprint to use CrystalNNFingerprint with
# structural order parameters (i.e., octahedral, tetrahedral)
# this allows getting the fingerprint for the whole structure
cnnf = SiteStatsFingerprint.from_preset("CrystalNNFingerprint_ops")

# add CrystalNNFingerprint to the dataframe 
df = cnnf.featurize_dataframe(df, "structure")

Does this help answer your question?

Best,
Alex

thank you for your reply, it help me.
one question is, what does the “first site in the structure” represent?

thanks!

A Structure object is effectively a list of atomic species and coordinates for multiple atoms. The first site is the first atom in the structure.