|
17 | 17 | from operator import itemgetter |
18 | 18 |
|
19 | 19 | import numpy as np |
20 | | -import pymatgen |
21 | | -from scipy.spatial import distance |
22 | 20 |
|
23 | 21 | from octadist.src import elements, popup |
24 | 22 |
|
@@ -127,6 +125,14 @@ def get_coord_cif(f): |
127 | 125 |
|
128 | 126 | warnings.filterwarnings("ignore") |
129 | 127 |
|
| 128 | + # Lazy import to avoid requiring pymatgen unless CIF parsing is used |
| 129 | + try: |
| 130 | + import pymatgen |
| 131 | + except ImportError as e: |
| 132 | + raise ImportError( |
| 133 | + "pymatgen is required to read CIF files. Install it or use a different input format." |
| 134 | + ) from e |
| 135 | + |
130 | 136 | # works only with pymatgen <= v2021.3.3 |
131 | 137 | structure = pymatgen.Structure.from_file(f) |
132 | 138 | atom = list(map(lambda x: elements.number_to_symbol(x), structure.atomic_numbers)) |
@@ -226,9 +232,12 @@ def get_coord_xyz(f): |
226 | 232 |
|
227 | 233 | atom = [] |
228 | 234 | for l in line: |
229 | | - # read atom on 1st column and insert to list |
| 235 | + # read atom symbol on 1st column using arbitrary whitespace splitter |
| 236 | + # handles spaces and tabs in XYZ files |
230 | 237 | l_strip = l.strip() |
231 | | - lst = l_strip.split(" ")[0] |
| 238 | + if not l_strip: |
| 239 | + continue |
| 240 | + lst = l_strip.split()[0] |
232 | 241 | atom.append(lst) |
233 | 242 |
|
234 | 243 | file = open(f, "r") |
@@ -967,6 +976,9 @@ def extract_octa(atom, coord, ref_index=0, cutoff_ref_ligand=2.8): |
967 | 976 | "index of the reference center atom is greater than the total number of atoms in the complex." |
968 | 977 | ) |
969 | 978 |
|
| 979 | + # Lazy import to avoid requiring scipy unless octa extraction is used |
| 980 | + from scipy.spatial import distance |
| 981 | + |
970 | 982 | dist_list = [] |
971 | 983 | for i in range(len(list(atom))): |
972 | 984 | dist = distance.euclidean(coord[ref_index], coord[i]) |
|
0 commit comments