Skip to content

Commit 074aca4

Browse files
authored
from_file method allows to switch to pymatgen (#80)
1 parent 0f3096a commit 074aca4

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

docs/source/how_to/creation_mutation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ Charges: [2. 0.]
224224

225225
### From Files
226226

227-
Load structures from various file formats:
227+
Load structures from various file formats, via the `from_file` method. It is possible to specify the parser engine between "ase" and "pymatgen".If the file is not a .cif or .mcif, the default is ase. To change it, you can pass the `parser="pymatgen"` input parameters to the method.
228228

229229
#### From CIF
230230

231231
```python
232-
# From CIF file
232+
# From CIF file ()
233233
structure = StructureData.from_file('path/to/your/structure.cif')
234234
print(f"Loaded from CIF: {structure.properties.formula}")
235235
```
@@ -587,7 +587,7 @@ Total charge: -1.0
587587

588588
```python
589589
# Load existing structure
590-
original = StructureData.from_file('structure.cif')
590+
original = StructureData.from_file('structure.cif', parser='pymatgen')
591591

592592
# Create mutable copy
593593
mutable = StructureBuilder(**original.to_dict())

src/aiida_atomistic/data/structure/getter_mixin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,14 @@ def from_file(
174174
cls,
175175
filename,
176176
format="cif",
177+
parser:str="ase",
177178
**kwargs):
178-
"""Load the structure from a file."""
179+
"""Load the structure from a file.
179180
180-
if format == 'mcif' or '.mcif' in filename:
181+
It is possible to specify the parser between ase or pymatgen, default is ase.
182+
"""
183+
184+
if format == 'mcif' or '.mcif' in filename or parser == "pymatgen":
181185
# in this case, we use pymatgen parser, because the ase one does not work properly for now.
182186
from pymatgen.io.cif import CifParser
183187
parser = CifParser(filename)

src/aiida_atomistic/data/structure/structure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def properties(self):
4545
from aiida_atomistic.data.structure.utils import build_sites_from_expanded_properties
4646
if "kind_names" in self.base.attributes.all:
4747
from aiida_atomistic.data.structure.utils_kinds import rebuild_site_lists_from_kind_lists
48-
attribute_lists = rebuild_site_lists_from_kind_lists(self.base.attributes.all)
49-
attributes = build_sites_from_expanded_properties(attribute_lists)
48+
attribute_lists_dict = rebuild_site_lists_from_kind_lists(self.base.attributes.all)
49+
attributes = build_sites_from_expanded_properties(attribute_lists_dict)
5050
else:
5151
attributes = build_sites_from_expanded_properties(self.base.attributes.all)
5252

src/aiida_atomistic/data/structure/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,9 @@ def order_k(k):
911911
def build_sites_from_expanded_properties(expanded):
912912
"""
913913
Build the structure dictionary from expanded site-wise lists of properties.
914+
915+
Expanded is a dictionary where each key corresponds to a property and the value is a list of values for each site,
916+
i.e. the format on which we store the properties in the database.
914917
"""
915918

916919
# Use all keys except positions if you want to exclude arrays, or specify your own

0 commit comments

Comments
 (0)