qzhu2017 / PyXtal

A code to generate atomic structure with symmetry
MIT License
234 stars 59 forks source link

[0.6.1] Error creating NH3 molecule #240

Closed Youjin1985 closed 6 months ago

Youjin1985 commented 6 months ago

In [1]: from pyxtal.molecule import pyxtal_molecule In [2]: pyxtal_molecule('NH3')

ValueError Traceback (most recent call last) Cell In[2], line 1 ----> 1 pyxtal_molecule('NH3')

File ~/.pyenv/versions/3.11.7/envs/matsci/lib/python3.11/site-packages/pyxtal/molecule.py:234, in pyxtal_molecule.init(self, mol, symmetrize, fix, torsions, seed, tm) 232 if len(mo) > 1: 233 if symmetrize: --> 234 pga = PointGroupAnalyzer(mo, 0.5) 235 mo = pga.symmetrize_molecule()["sym_mol"] 236 self.mol = mo

File ~/.pyenv/versions/3.11.7/envs/matsci/lib/python3.11/site-packages/pymatgen/symmetry/analyzer.py:964, in PointGroupAnalyzer.init(self, mol, tolerance, eigen_tolerance, matrix_tolerance) 962 self.eig_tol = eigen_tolerance 963 self.mat_tol = matrix_tolerance --> 964 self._analyze() 965 if self.sch_symbol in ["C1v", "C1h"]: 966 self.sch_symbol = "Cs"

File ~/.pyenv/versions/3.11.7/envs/matsci/lib/python3.11/site-packages/pymatgen/symmetry/analyzer.py:1009, in PointGroupAnalyzer._analyze(self) 1007 else: 1008 logger.debug("Symmetric top molecule detected") -> 1009 self._proc_sym_top()

File ~/.pyenv/versions/3.11.7/envs/matsci/lib/python3.11/site-packages/pymatgen/symmetry/analyzer.py:1048, in PointGroupAnalyzer._proc_sym_top(self) 1046 logger.debug(f"Eigenvalues = {self.eigvals}.") 1047 unique_axis = self.principal_axes[ind] -> 1048 self._check_rot_sym(unique_axis) 1049 logger.debug(f"Rotation symmetries = {self.rot_sym}") 1050 if len(self.rot_sym) > 0:

File ~/.pyenv/versions/3.11.7/envs/matsci/lib/python3.11/site-packages/pymatgen/symmetry/analyzer.py:1172, in PointGroupAnalyzer._check_rot_sym(self, axis) 1166 def _check_rot_sym(self, axis): 1167 """Determines the rotational symmetry about supplied axis. 1168 1169 Used only for symmetric top molecules which has possible rotational symmetry 1170 operations > 2. 1171 """ -> 1172 min_set = self._get_smallest_set_not_on_axis(axis) 1173 max_sym = len(min_set) 1174 for i in range(max_sym, 0, -1):

File ~/.pyenv/versions/3.11.7/envs/matsci/lib/python3.11/site-packages/pymatgen/symmetry/analyzer.py:1164, in PointGroupAnalyzer._get_smallest_set_not_on_axis(self, axis) 1161 if len(valid_set) > 0: 1162 valid_sets.append(valid_set) -> 1164 return min(valid_sets, key=len)

ValueError: min() arg is an empty sequence

Youjin1985 commented 6 months ago

Meanwhile pyxtal_molecule('NH3', symmetrize=False) works, and default pymatgen PointGroupAnalyzer tolerance=0.3 works for NH3, problem is with tolerance 0.5 inside pyxtal This issue makes impossible to generate random crystals with some molecules, for example: my_crystal.from_random(3, 36, [nh3], [4]) will fail as there is no way to pass tolerance parameter to internal code. May I suggest to decrease tolerance at line 234 of pyxtal/molecule.py or change from_random() to accept either tolerance or keyword to turn off molecule symmetrization?