Newbie here, pymatgen structure has has no attribute 'find_primitive_structure'

Hi,

I’ve just started familiarizing myself with pymatgen, and naturally started by going through the code in the documentation.
https://pymatgen.org/usage.html
However, when I run the exact same code using the correct version of pymatgen, I get an the error in the title.

The issue seems to me to be that my Structure is of the mutable Structure type, while the find_primitive_type method exists only for the immutable IStructure.
https://pymatgen.org/pymatgen.core.structure.html#module-pymatgen.core.structure
Looking at the source on my computer seems to confirm this, the class is Structure, with different methods.
But why is my structure of a different class than the one in the documentation, when I am running the same code, using the correct version of pymatgen? How do I convert between the two?

Code I run:

from pymatgen import Lattice, Structure
import pymatgen
print(pymatgen.'__version__')
coords = [[0, 0, 0], [0.75,0.5,0.75]]
lattice = Lattice.from_parameters(a=3.84, b=3.84, c=3.84, alpha=120,
                                  beta=90, gamma=60)
structure = Structure(lattice, ["Si", "Si"], coords)
print(type(structure))
structure[1] = "F"
# Change species and coordinates (fractional assumed for Structures,
# cartesian for Molecules)
structure[1] = "Cl", [0.51, 0.51, 0.51]
# Structure/Molecule also supports typical list-like operators,
# such as reverse, extend, pop, index, count.
structure.reverse()
structure.append("F", [0.9, 0.9, 0.9])
print(structure)
# Make a supercell
structure.make_supercell([2, 2, 2])
#Find a primitive version of the Structure
structure.find_primitive_structure()

Output:
2019.10.16
<class ‘pymatgen.core.structure.Structure’>
Full Formula (Si1 Cl1 F1)
Reduced Formula: SiClF
abc : 3.840000 3.840000 3.840000
angles: 120.000000 90.000000 60.000000
Sites (3)

SP a b c


0 Cl 0.51 0.51 0.51
1 Si 0 0 0
2 F 0.9 0.9 0.9
Traceback (most recent call last):
File “C:\Users#################\test.py”, line 32, in
main()
File “C:\Users#################\test.py”, line 30, in main
structure.find_primitive_structure()
AttributeError: ‘Structure’ object has no attribute ‘find_primitive_structure’

Hi @Pinniped,

Welcome to the forum! You have a typo, the correct method is get_primitive_structure() not find_primitive_structure().

Best,

Matt

Thank you, this solved the issue.

First I was feeling quite dumb here, but turns out that the documentation was out of date, as I found out over on the pymatgen forums.

Best,
Pinniped

Ah that explains it. I just checked the documentation myself and saw it was correct, I didn’t realise it had been fixed today :slight_smile: