From 1e299c75b947aeb43b0fb2d565e2ff339e1df5d3 Mon Sep 17 00:00:00 2001 From: Corin Wagen Date: Wed, 10 Jan 2024 09:48:44 -0500 Subject: [PATCH] modify smiles stuff --- cctk/molecule.py | 9 ++++++--- setup.py | 4 ++-- test/test_molecule.py | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cctk/molecule.py b/cctk/molecule.py index 0db733c..8e2df70 100644 --- a/cctk/molecule.py +++ b/cctk/molecule.py @@ -1588,13 +1588,16 @@ def new_from_smiles(cls, smiles, max_num_atoms=None): try: status1 = Chem.EmbedMolecule(rdkm, maxAttempts=5000) assert status1 >= 0 - status2 = Chem.MMFFOptimizeMolecule(rdkm, maxIters=200) - assert status2 >= 0 except Exception: status1 = Chem.EmbedMolecule(rdkm, maxAttempts=5000, useRandomCoords=True) - assert status1 >= 0 + if status1 < 0: + raise ValueError(f"Cannot embed molecule ``{smiles}``!") + + try: status2 = Chem.MMFFOptimizeMolecule(rdkm, maxIters=200) assert status2 >= 0 + except AssertionError: + pass nums = [] for atom in rdkm.GetAtoms(): diff --git a/setup.py b/setup.py index 4ddb669..27c3ae4 100644 --- a/setup.py +++ b/setup.py @@ -11,13 +11,13 @@ packages=["cctk", "cctk.data", "cctk.groups"], # include_package_data=True, package_data={"cctk.data": ["*"], "cctk.groups": ["*"],}, - version="v0.2.21", + version="v0.2.22", license="Apache 2.0", description="computational chemistry toolkit", author="Corin Wagen and Eugene Kwan", author_email="corin.wagen@gmail.com", url="https://github.com/ekwan/cctk", - download_url="https://github.com/ekwan/cctk/archive/v0.2.21.tar.gz", + download_url="https://github.com/ekwan/cctk/archive/v0.2.22.tar.gz", install_requires=["numpy", "networkx", "importlib_resources", "scipy", "pyahocorasick", "basis_set_exchange", "pyyaml"], long_description=long_description, long_description_content_type='text/markdown', diff --git a/test/test_molecule.py b/test/test_molecule.py index 2fcc104..5e7e49a 100644 --- a/test/test_molecule.py +++ b/test/test_molecule.py @@ -159,6 +159,12 @@ def test_smiles_utils(self): mol = cctk.Molecule.new_from_smiles("[OH3+]") self.assertEqual(mol.charge, 1) + mol = cctk.Molecule.new_from_smiles("C1[Br+]C1(C)C") + self.assertEqual(mol.charge, 1) + + mol = cctk.Molecule.new_from_smiles("C1[Hg+](Cl)C1(C)C") + self.assertEqual(mol.charge, 1) + def test_renumber(self): mol = self.load_molecule() mol2 = mol.swap_atom_numbers(1, 2)