Skip to content

Commit dc1585d

Browse files
authored
Merge branch 'main' into fix/avoid_unnecessary_julia
2 parents f184fac + 22f5930 commit dc1585d

File tree

14 files changed

+110
-65
lines changed

14 files changed

+110
-65
lines changed

.conda/meta.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ requirements:
3030
- cairocffi
3131
- cantera >=2.3.0
3232
- cclib >=1.6.3
33-
- chemprop
3433
- coolprop
3534
- coverage
3635
- cython >=0.25.2

arkane/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ def update_species_attributes(self, species=None):
191191
self.multiplicity = species.molecule[0].multiplicity
192192
self.formula = species.molecule[0].get_formula()
193193
try:
194-
inchi = to_inchi(species.molecule[0], backend='try-all', aug_level=0)
194+
inchi = to_inchi(species.molecule[0], backend='openbabel-first', aug_level=0)
195195
except ValueError:
196196
inchi = ''
197197
try:
198-
inchi_key = to_inchi_key(species.molecule[0], backend='try-all', aug_level=0)
198+
inchi_key = to_inchi_key(species.molecule[0], backend='openbabel-first', aug_level=0)
199199
except ValueError:
200200
inchi_key = ''
201201
self.inchi = inchi

environment.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# Changelog:
1515
# - May 15, 2023 Added this changelog, added inline documentation,
1616
# made dependency list more explicit (@JacksonBurns).
17+
# - October 16, 2023 Switched RDKit and descripatastorus to conda-forge,
18+
# moved diffeqpy to pip and (temporarily) removed chemprop
1719
# - Mar 11, 2024 Removed Julia dependencies, now considered optional
1820
#
1921
name: rmg_env
@@ -45,13 +47,14 @@ dependencies:
4547
- conda-forge::mopac
4648
- conda-forge::cclib >=1.6.3,!=1.8.0
4749
- conda-forge::openbabel >= 3
50+
- conda-forge::rdkit >=2022.09.1
4851

4952
# Python tools
5053
- python >=3.7
5154
- coverage
5255
- cython >=0.25.2
5356
- scikit-learn
54-
- scipy
57+
- scipy <1.11
5558
- numpy >=1.10.0
5659
- pydot
5760
- jinja2
@@ -84,15 +87,6 @@ dependencies:
8487
- rmg::pyrdl
8588
- rmg::symmetry
8689

87-
# packages we would like to stop maintaining (and why)
88-
- rmg::chemprop
89-
# Our build of this is version 0.0.1 (!!) and we are using parts
90-
# of the API that are now gone. Need a serious PR to fix this.
91-
92-
- rmg::rdkit >=2020.03.3.0
93-
# We should use the official channel, not sure how difficult this
94-
# change will be.
95-
9690
# conda mutex metapackage
9791
- nomkl
9892

rmgpy/ml/estimator.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,27 @@
3232
from argparse import Namespace
3333
from typing import Callable, Union
3434

35+
chemprop = None
3536
try:
3637
import chemprop
3738
except ImportError as e:
38-
chemprop = None
3939
chemprop_exception = e
4040
import numpy as np
4141

4242
from rmgpy.molecule import Molecule
4343
from rmgpy.species import Species
4444
from rmgpy.thermo import ThermoData
4545

46+
ADMONITION = """
47+
Support for predicting thermochemistry using chemprop has been temporarily removed
48+
from RMG, pending official chemprop support for Python 3.11 and newer.
49+
50+
To use chemprop and RMG, install a previous version of RMG (3.1.1 or earlier).
51+
52+
See the link below for status of re-integration of chemprop:
53+
https://github.com/ReactionMechanismGenerator/RMG-Py/issues/2559
54+
"""
55+
4656

4757
class MLEstimator:
4858
"""
@@ -118,7 +128,7 @@ def load_estimator(model_dir: str) -> Callable[[str], np.ndarray]:
118128
if chemprop is None:
119129
# Delay chemprop ImportError until we actually try to use it
120130
# so that RMG can load successfully without chemprop.
121-
raise chemprop_exception
131+
raise RuntimeError(ADMONITION + "\nOriginal Exception:\n" + str(chemprop_exception))
122132

123133
args = Namespace() # Simple class to hold attributes
124134

rmgpy/molecule/molecule.pxd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@ cdef class Molecule(Graph):
224224
bint raise_charge_exception=?, bint check_consistency=?)
225225

226226
cpdef from_xyz(self, np.ndarray atomic_nums, np.ndarray coordinates, float critical_distance_factor=?, bint raise_atomtype_exception=?)
227-
228-
cpdef str to_inchi(self)
229227

230-
cpdef str to_augmented_inchi(self)
228+
cpdef str to_inchi(self, str backend=?)
229+
230+
cpdef str to_augmented_inchi(self, str backend=?)
231231

232-
cpdef str to_inchi_key(self)
232+
cpdef str to_inchi_key(self, str backend=?)
233233

234-
cpdef str to_augmented_inchi_key(self)
234+
cpdef str to_augmented_inchi_key(self, str backend=?)
235235

236236
cpdef str to_smiles(self)
237237

rmgpy/molecule/molecule.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,9 +1768,13 @@ def _repr_png_(self):
17681768
os.unlink(temp_file_name)
17691769
return png
17701770

1771-
def from_inchi(self, inchistr, backend='try-all', raise_atomtype_exception=True):
1771+
def from_inchi(self, inchistr, backend='openbabel-first', raise_atomtype_exception=True):
17721772
"""
17731773
Convert an InChI string `inchistr` to a molecular structure.
1774+
1775+
RDKit and Open Babel are the two backends used in RMG. It is possible to use a
1776+
single backend or try different backends in sequence. The available options for the ``backend``
1777+
argument: 'openbabel-first'(default), 'rdkit-first', 'rdkit', or 'openbabel'.
17741778
"""
17751779
translator.from_inchi(self, inchistr, backend, raise_atomtype_exception=raise_atomtype_exception)
17761780
return self
@@ -1782,9 +1786,13 @@ def from_augmented_inchi(self, aug_inchi, raise_atomtype_exception=True):
17821786
translator.from_augmented_inchi(self, aug_inchi, raise_atomtype_exception=raise_atomtype_exception)
17831787
return self
17841788

1785-
def from_smiles(self, smilesstr, backend='try-all', raise_atomtype_exception=True):
1789+
def from_smiles(self, smilesstr, backend='openbabel-first', raise_atomtype_exception=True):
17861790
"""
17871791
Convert a SMILES string `smilesstr` to a molecular structure.
1792+
1793+
RDKit and Open Babel are the two backends used in RMG. It is possible to use a
1794+
single backend or try different backends in sequence. The available options for the ``backend``
1795+
argument: 'openbabel-first'(default), 'rdkit-first', 'rdkit', or 'openbabel'.
17881796
"""
17891797
translator.from_smiles(self, smilesstr, backend, raise_atomtype_exception=raise_atomtype_exception)
17901798
return self
@@ -1863,62 +1871,78 @@ def to_single_bonds(self, raise_atomtype_exception=True):
18631871
new_mol.update_atomtypes(raise_exception=raise_atomtype_exception)
18641872
return new_mol
18651873

1866-
def to_inchi(self):
1874+
def to_inchi(self, backend='rdkit-first'):
18671875
"""
18681876
Convert a molecular structure to an InChI string. Uses
18691877
`RDKit <http://rdkit.org/>`_ to perform the conversion.
18701878
Perceives aromaticity.
1871-
1879+
18721880
or
1873-
1881+
18741882
Convert a molecular structure to an InChI string. Uses
18751883
`OpenBabel <http://openbabel.org/>`_ to perform the conversion.
1884+
1885+
It is possible to use a single backend or try different backends in sequence.
1886+
The available options for the ``backend`` argument: 'rdkit-first'(default),
1887+
'openbabel-first', 'rdkit', or 'openbabel'.
18761888
"""
18771889
try:
1878-
return translator.to_inchi(self)
1890+
return translator.to_inchi(self, backend=backend)
18791891
except:
18801892
logging.exception(f"Error for molecule \n{self.to_adjacency_list()}")
18811893
raise
18821894

1883-
def to_augmented_inchi(self):
1895+
def to_augmented_inchi(self, backend='rdkit-first'):
18841896
"""
18851897
Adds an extra layer to the InChI denoting the multiplicity
18861898
of the molecule.
1887-
1899+
18881900
Separate layer with a forward slash character.
1901+
1902+
RDKit and Open Babel are the two backends used in RMG. It is possible to use a
1903+
single backend or try different backends in sequence. The available options for the ``backend``
1904+
argument: 'rdkit-first'(default), 'openbabel-first', 'rdkit', or 'openbabel'.
18891905
"""
18901906
try:
1891-
return translator.to_inchi(self, aug_level=2)
1907+
return translator.to_inchi(self, backend=backend, aug_level=2)
18921908
except:
18931909
logging.exception(f"Error for molecule \n{self.to_adjacency_list()}")
18941910
raise
18951911

1896-
def to_inchi_key(self):
1912+
def to_inchi_key(self, backend='rdkit-first'):
18971913
"""
18981914
Convert a molecular structure to an InChI Key string. Uses
18991915
`OpenBabel <http://openbabel.org/>`_ to perform the conversion.
1900-
1901-
or
1902-
1916+
1917+
or
1918+
19031919
Convert a molecular structure to an InChI Key string. Uses
19041920
`RDKit <http://rdkit.org/>`_ to perform the conversion.
1921+
1922+
It is possible to use a single backend or try different backends in sequence.
1923+
The available options for the ``backend`` argument: 'rdkit-first'(default),
1924+
'openbabel-first', 'rdkit', or 'openbabel'.
19051925
"""
19061926
try:
1907-
return translator.to_inchi_key(self)
1927+
return translator.to_inchi_key(self, backend=backend)
19081928
except:
19091929
logging.exception(f"Error for molecule \n{self.to_adjacency_list()}")
19101930
raise
19111931

1912-
def to_augmented_inchi_key(self):
1932+
def to_augmented_inchi_key(self, backend='rdkit-first'):
19131933
"""
19141934
Adds an extra layer to the InChIKey denoting the multiplicity
19151935
of the molecule.
19161936
19171937
Simply append the multiplicity string, do not separate by a
19181938
character like forward slash.
1939+
1940+
RDKit and Open Babel are the two backends used in RMG. It is possible to use a
1941+
single backend or try different backends in sequence. The available options for the ``backend``
1942+
argument: 'rdkit-first'(default), 'openbabel-first', 'rdkit', or 'openbabel'.
19191943
"""
19201944
try:
1921-
return translator.to_inchi_key(self, aug_level=2)
1945+
return translator.to_inchi_key(self, backend=backend, aug_level=2)
19221946
except:
19231947
logging.exception(f"Error for molecule \n{self.to_adjacency_list()}")
19241948
raise

rmgpy/molecule/translator.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def to_inchi(mol, backend='rdkit-first', aug_level=0):
169169
Uses RDKit or OpenBabel for conversion.
170170
171171
Args:
172-
backend choice of backend, 'try-all', 'rdkit', or 'openbabel'
172+
backend choice of backend, 'rdkit-first' (default), 'openbabel-first', 'rdkit', or 'openbabel'
173173
aug_level level of augmentation, 0, 1, or 2
174174
"""
175175
cython.declare(inchi=str, ulayer=str, player=str, mlayer=str)
@@ -205,7 +205,7 @@ def to_inchi_key(mol, backend='rdkit-first', aug_level=0):
205205
Uses RDKit or OpenBabel for conversion.
206206
207207
Args:
208-
backend choice of backend, 'try-all', 'rdkit', or 'openbabel'
208+
backend choice of backend, 'rdkit-first' (default), 'openbabel-first', 'rdkit', or 'openbabel'
209209
aug_level level of augmentation, 0, 1, or 2
210210
"""
211211
cython.declare(key=str, ulayer=str, player=str, mlayer=str)
@@ -274,11 +274,11 @@ def to_smiles(mol, backend='default'):
274274
return output
275275

276276

277-
def from_inchi(mol, inchistr, backend='try-all', raise_atomtype_exception=True):
277+
def from_inchi(mol, inchistr, backend='openbabel-first', raise_atomtype_exception=True):
278278
"""
279279
Convert an InChI string `inchistr` to a molecular structure. Uses
280-
a user-specified backend for conversion, currently supporting
281-
rdkit (default) and openbabel.
280+
a user-specified backend for conversion, currently supporting 'openbabel-first' (default), rdkit-first,
281+
rdkit, and openbabel.
282282
"""
283283
if inchiutil.INCHI_PREFIX in inchistr:
284284
return _read(mol, inchistr, 'inchi', backend, raise_atomtype_exception=raise_atomtype_exception)
@@ -325,11 +325,11 @@ def from_smarts(mol, smartsstr, backend='rdkit', raise_atomtype_exception=True):
325325
return _read(mol, smartsstr, 'sma', backend, raise_atomtype_exception=raise_atomtype_exception)
326326

327327

328-
def from_smiles(mol, smilesstr, backend='try-all', raise_atomtype_exception=True):
328+
def from_smiles(mol, smilesstr, backend='openbabel-first', raise_atomtype_exception=True):
329329
"""
330330
Convert a SMILES string `smilesstr` to a molecular structure. Uses
331-
a user-specified backend for conversion, currently supporting
332-
rdkit (default) and openbabel.
331+
a user-specified backend for conversion, currently supporting openbabel-first (default), rdkit-first,
332+
rdkit and openbabel.
333333
"""
334334
return _read(mol, smilesstr, 'smi', backend, raise_atomtype_exception=raise_atomtype_exception)
335335

@@ -569,14 +569,14 @@ def _get_backend_list(backend):
569569
"""
570570
if not isinstance(backend, str):
571571
raise ValueError("The backend argument should be a string. "
572-
"Accepted values are 'try-all', 'rdkit-first', 'rdkit', and 'openbabel'")
572+
"Accepted values are 'openbabel-first', 'rdkit-first', 'rdkit', and 'openbabel'")
573573
backend = backend.strip().lower()
574-
if backend == 'try-all':
574+
if backend == 'openbabel-first':
575575
return BACKENDS
576576
elif backend == 'rdkit-first':
577577
return reversed(BACKENDS)
578578
elif backend in ['rdkit', 'openbabel']:
579579
return [backend]
580580
else:
581581
raise ValueError("Unrecognized value for backend argument. "
582-
"Accepted values are 'try-all', 'rdkit-first', 'rdkit', and 'openbabel'")
582+
"Accepted values are 'openbabel-first', 'rdkit-first', 'rdkit', and 'openbabel'")

rmgpy/qm/molecule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,11 @@ def load_thermo_data(self):
520520
self.qm_data = local_context["qmData"]
521521
return thermo
522522

523-
def get_augmented_inchi_key(self):
523+
def get_augmented_inchi_key(self, backend='rdkit-first'):
524524
"""
525525
Returns the augmented InChI from self.molecule
526526
"""
527-
return self.molecule.to_augmented_inchi_key()
527+
return self.molecule.to_augmented_inchi_key(backend=backend)
528528

529529
def get_mol_file_path_for_calculation(self, attempt):
530530
"""

rmgpy/species.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,17 +740,17 @@ def copy(self, deep=False):
740740

741741
return other
742742

743-
def get_augmented_inchi(self):
743+
def get_augmented_inchi(self, backend='rdkit-first'):
744744
if self.aug_inchi is None:
745-
self.aug_inchi = self.generate_aug_inchi()
745+
self.aug_inchi = self.generate_aug_inchi(backend=backend)
746746
return self.aug_inchi
747747

748-
def generate_aug_inchi(self):
748+
def generate_aug_inchi(self, backend='rdkit-first'):
749749
candidates = []
750750
self.generate_resonance_structures()
751751
for mol in self.molecule:
752752
try:
753-
cand = [mol.to_augmented_inchi(), mol]
753+
cand = [mol.to_augmented_inchi(backend=backend), mol]
754754
except ValueError:
755755
pass # not all resonance structures can be parsed into InChI (e.g. if containing a hypervalance atom)
756756
else:

scripts/checkModels.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@ def initialize_log(verbose, log_file_name='checkModels.log'):
284284
`verbose` parameter is an integer specifying the amount of log text seen
285285
at the console; the levels correspond to those of the :data:`logging` module.
286286
"""
287+
# since RDKit 2022.03.1, logging is done using the Python logger instead of the
288+
# Cout streams. This does not affect running RMG normally, but this testing file
289+
# only works properly if it is the only logger
290+
# see https://github.com/rdkit/rdkit/pull/4846 for the changes in RDKit
291+
292+
# clear all other existing loggers
293+
# https://stackoverflow.com/a/12158233
294+
for handler in logging.root.handlers[:]:
295+
logging.root.removeHandler(handler)
296+
297+
# once moved to a more recent python (at least 3.8), just add force=true to this statement
298+
# and remove the above
287299
logging.basicConfig(
288300
filename=log_file_name,
289301
filemode='w',

0 commit comments

Comments
 (0)