|
2 | 2 | import os |
3 | 3 | import random |
4 | 4 | import importlib |
| 5 | +from tempfile import NamedTemporaryFile |
5 | 6 |
|
6 | 7 | import numpy as np |
7 | 8 | import pytest |
@@ -102,13 +103,47 @@ def test_get_structures(self, mpr): |
102 | 103 | assert len(structs) > 0 |
103 | 104 |
|
104 | 105 | def test_find_structure(self, mpr): |
105 | | - path = os.path.join(MAPIClientSettings().TEST_FILES, "Si_mp_149.cif") |
106 | | - data = mpr.find_structure(path) |
107 | | - assert isinstance(data, str) and data == "mp-149" |
108 | | - |
109 | | - s = CifParser(path).get_structures()[0] |
110 | | - data = mpr.find_structure(s) |
111 | | - assert isinstance(data, str) and data == "mp-149" |
| 106 | + cif_str = """# mp-111 |
| 107 | +data_Ne |
| 108 | +_symmetry_space_group_name_H-M 'P 1' |
| 109 | +_cell_length_a 2.96632550 |
| 110 | +_cell_length_b 2.96632684 |
| 111 | +_cell_length_c 2.96632748 |
| 112 | +_cell_angle_alpha 60.00001414 |
| 113 | +_cell_angle_beta 59.99999919 |
| 114 | +_cell_angle_gamma 60.00001422 |
| 115 | +_symmetry_Int_Tables_number 1 |
| 116 | +_chemical_formula_structural Ne |
| 117 | +_chemical_formula_sum Ne1 |
| 118 | +_cell_volume 18.45618751 |
| 119 | +_cell_formula_units_Z 1 |
| 120 | +loop_ |
| 121 | + _symmetry_equiv_pos_site_id |
| 122 | + _symmetry_equiv_pos_as_xyz |
| 123 | + 1 'x, y, z' |
| 124 | +loop_ |
| 125 | + _atom_site_type_symbol |
| 126 | + _atom_site_label |
| 127 | + _atom_site_symmetry_multiplicity |
| 128 | + _atom_site_fract_x |
| 129 | + _atom_site_fract_y |
| 130 | + _atom_site_fract_z |
| 131 | + _atom_site_occupancy |
| 132 | + Ne Ne0 1 0.00000000 0.00000000 -0.00000000 1 |
| 133 | +""" |
| 134 | + temp_file = NamedTemporaryFile(suffix=".cif") |
| 135 | + with open(temp_file.name, "wt") as f: |
| 136 | + f.write(cif_str) |
| 137 | + f.seek(0) |
| 138 | + |
| 139 | + for struct_or_path in ( |
| 140 | + temp_file.name, |
| 141 | + CifParser.from_str(cif_str).parse_structures(primitive=True)[0], |
| 142 | + ): |
| 143 | + data = mpr.find_structure(struct_or_path) |
| 144 | + assert isinstance(data, str) and data == "mp-111" |
| 145 | + |
| 146 | + f.close() |
112 | 147 |
|
113 | 148 | def test_get_bandstructure_by_material_id(self, mpr): |
114 | 149 | bs = mpr.get_bandstructure_by_material_id("mp-149") |
|
0 commit comments