-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial 12
The Python Materials Genomics (PyMatGen) toolkit is one of the most powerful Python libraries in computational materials science.
Developed as a core part of the Materials Project, PyMatGen helps you analyze, manipulate, and generate crystal structures, perform symmetry analysis, and more.
๐ Official Website: https://pymatgen.org/
๐น YouTube Tutorials: Materials Virtual Lab
To install PyMatGen on your Mac or on the POWER cluster, activate your mamba environment and run:
mamba install pymatgenโณ Note: This may take a few minutes. PyMatGen has several dependencies.
Let's start with a quick check to see if PyMatGen works:
from pymatgen.symmetry.groups import SpaceGroup
symmetrynumber = 10
print(SpaceGroup.from_int_number(symmetrynumber).symbol)This should print the HermannโMauguin symbol for space group #10.
Now, letโs extend that to print all 230 space group symbols:
from pymatgen.symmetry.groups import SpaceGroup
for sg_num in range(1, 231):
sg = SpaceGroup.from_int_number(sg_num)
print(sg)PyMatGen can also help you compare two structures, either fully or partially (e.g. ignoring atomic species).
from pymatgen.core import Structure
from pymatgen.analysis.structure_matcher import StructureMatcher
structure1 = Structure.from_file("path/to/file/my_structure.cif")
structure2 = Structure.from_file("path/to/file/target_structure.cif")
matcher = StructureMatcher()
print(matcher.fit(structure1, structure2)) # Returns True or False๐ ๏ธ You can tune the comparison with parameters like:
ltol # Length tolerance (default: 0.2)
stol # Site tolerance (default: 0.3)
angle_tol # Angle tolerance in degrees (default: 5)You can also compare structures ignoring the atom types, to see if they share the same framework (e.g. Si and C in diamond structure):
from pymatgen.core import Structure
from pymatgen.analysis.structure_matcher import StructureMatcher, FrameworkComparator
diamond = Structure.from_file("path/to/file/diamond.cif")
silicon = Structure.from_file("path/to/file/Si.cif")
matcher = StructureMatcher(comparator=FrameworkComparator())
print(matcher.fit(diamond, silicon)) # Should return TrueIf you've reached this point:
โ
PyMatGen is installed and working
โ
You can analyze symmetry and compare structures
โ
You're ready for more advanced structure analysis!
๐ Continue to Tutorial 13 โ