pytmatgen structure not abipy?
jzwanzig opened this issue · comments
abipy/abipy/scripts/abistruct.py
Line 652 in 6299326
This line seems to fail because the structure in question does not have the abi_string attribute, it seems to be created as a pymatgen structure but without the abipy extensions that would include the abi_string attribute
Hi @jzwanzig,
it seems to be created as a pymatgen structure but without the abipy extensions that would include the abi_string attribute
Yes, the get_primitive method of pymatgen structure should use self.__class__
when building a new object so that
inheritance is preserved. There are however cases in which the method uses pymatgen.core.Structure to construct the primitive structure so we don't get an AbipyStructure.
Quick fix:
diff --git a/abipy/scripts/abistruct.py b/abipy/scripts/abistruct.py
index 4bdd6b08..1b75185f 100755
--- a/abipy/scripts/abistruct.py
+++ b/abipy/scripts/abistruct.py
@@ -646,6 +646,8 @@ def main():
elif options.command == "primitive":
structure = abilab.Structure.from_file(options.filepath)
primitive = structure.get_primitive_structure(tolerance=0.25, use_site_props=False, constrain_latt=None)
+ # Cast to abipy structure because get_primitive may break inheritance.
+ primitive = abilab.Structure.as_structure(primitive)
separator = "\n" + 90 * "="
print("\nInitial structure:\n", structure, separator)
print("\nPrimitive structure returned by pymatgen:\n", primitive, separator)