Skip to content

Commit

Permalink
Merge pull request #3 from fxcoudert/load_structure
Browse files Browse the repository at this point in the history
Document and test the loading of JSON files
  • Loading branch information
adosar authored May 6, 2024
2 parents 29a0f1e + 8babee7 commit a067771
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/moxel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,18 @@ def __init__(self, grid_size=25, cutoff=10, epsilon=50, sigma=2.5):
self.epsilon = epsilon
self.sigma = sigma

def load_structure(self, cif_pathname):
def load_structure(self, pathname):
r"""
Load a crystal structure from a ``.cif`` file.
Load a crystal structure from a file in a format supported by pymatgen
(CIF, JSON, etc.)
Parameters
----------
cif_pathname : str
Pathname to the ``.cif`` file.
pathname : str
Pathname to the file.
"""
self.structure = Structure.from_file(cif_pathname)
self.structure_name = Path(cif_pathname).stem
self.structure = Structure.from_file(pathname)
self.structure_name = Path(pathname).stem

def calculate(self, cubic_box=False, length=30, potential='lj', n_jobs=None):
r"""
Expand Down
1 change: 1 addition & 0 deletions tests/CIFs/MnH28C26(N2Cl)2.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ def test_batch_clean(self):
# Check that the names have been correctly stored.
self.assertEqual([names[i] for i in filled_idx], clean_names)

def test_load_file(self):
cif_dir = 'tests/CIFs'

grid = Grid()
grid.load_structure(f'{cif_dir}/IRMOF-1.cif')

grid = Grid()
grid.load_structure(f'{cif_dir}/MnH28C26(N2Cl)2.json')


if __name__ == '__main__':
unittest.main()

0 comments on commit a067771

Please sign in to comment.