Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a species constraint for the max number of rings fused together #2606

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion documentation/source/users/rmg/input.rst
Expand Up @@ -993,7 +993,7 @@ all of RMG's reaction families. ::
maximumRadicalElectrons=2,
maximumSingletCarbenes=1,
maximumCarbeneRadicals=0,
maximumIsotopicAtoms=2,
maximumFusedRings=3,
allowSingletO2 = False,
speciesCuttingThreshold=20,
)
Expand All @@ -1003,6 +1003,8 @@ from either the input file, seed mechanisms, or reaction libraries to bypass the
Note that this should be done with caution, since the constraints will still apply to subsequent
products that form.

``maximumFusedRings`` is the maximum number of rings in any fused ring system in the species.

By default, the ``allowSingletO2`` flag is set to ``False``. See :ref:`representing_oxygen` for more information.

Note that ``speciesCuttingThreshold`` is set by default to 20 heavy atoms. This means that if a species containing
Expand Down
4 changes: 0 additions & 4 deletions documentation/source/users/rmg/modules/isotopes.rst
Expand Up @@ -49,10 +49,6 @@ not match the same depository reactions, leading to inconsistent kinetics. If
degeneracy errors arise when generating reactions from scratch, try using this
option to see if it reduces errors in degeneracy.

The arguement ``--maximumIsotopicAtoms [integer]`` limits the number of enriched
atoms in any isotopologue in the model. This is beneficial for decreasing model
size, runtime of model creation and runtime necessary for analysis.

Adding kinetic isotope effects which are described in this paper can be obtained
through the argument ``--kineticIsotopeEffect simple``. Currently this is the
only supported method, though this can be extended to other effects.
Expand Down
2 changes: 0 additions & 2 deletions examples/rmg/MR_test/input.py
Expand Up @@ -305,7 +305,5 @@
#If this is false or missing, RMG will throw an error if the more less-stable form of O2 is entered
#which doesn't react in the RMG system. normally input O2 as triplet with SMILES [O][O]
#allowSingletO2=False,
# maximum allowed number of non-normal isotope atoms:
#maximumIsotopicAtoms=2,
)

2 changes: 0 additions & 2 deletions examples/rmg/commented/input.py
Expand Up @@ -285,8 +285,6 @@
# If this is false or missing, RMG will throw an error if the more less-stable form of O2 is entered
# which doesn't react in the RMG system. normally input O2 as triplet with SMILES [O][O]
# allowSingletO2=False,
# maximum allowed number of non-normal isotope atoms:
# maximumIsotopicAtoms=2,
)

# optional block allows thermo to be estimated through quantum calculations
Expand Down
7 changes: 7 additions & 0 deletions rmgpy/constraints.py
Expand Up @@ -31,6 +31,7 @@

from rmgpy.species import Species


def pass_cutting_threshold(species):
"""
Pass in either a `Species` or `Molecule` object and checks whether it passes
Expand Down Expand Up @@ -58,6 +59,7 @@ def pass_cutting_threshold(species):

return False


def fails_species_constraints(species):
"""
Pass in either a `Species` or `Molecule` object and checks whether it passes
Expand Down Expand Up @@ -139,4 +141,9 @@ def fails_species_constraints(species):
if struct.get_singlet_carbene_count() > 0 and struct.get_radical_count() > max_carbene_radicals:
return True

max_fused_rings = species_constraints.get('maximumFusedRings', -1)
if max_fused_rings != -1 and struct.is_cyclic():
if struct.get_ring_count_in_largest_fused_ring_system() > max_fused_rings:
return True

return False
19 changes: 19 additions & 0 deletions rmgpy/molecule/molecule.py
Expand Up @@ -2926,6 +2926,25 @@ def get_desorbed_molecules(self):

return desorbed_molecules

def get_ring_count_in_largest_fused_ring_system(self) -> int:
"""
Get the number of rings in the largest fused ring system in the molecule.
"""
cython.declare(ring_counts=list, rings=list, ring_count=int)
polycycles = self.get_polycycles()
ring_counts = list()
for polycycle in polycycles:
rings, ring_count = list(), 0
for atom in polycycle:
cycles = self.get_all_cycles(atom)
for cycle in cycles:
if cycle not in rings:
rings.append(cycle)
ring_count += 1
ring_counts.append(ring_count)
return max(ring_counts) if len(ring_counts) else 0


# this variable is used to name atom IDs so that there are as few conflicts by
# using the entire space of integer objects
atom_id_counter = -2 ** 15
1 change: 1 addition & 0 deletions rmgpy/rmg/input.py
Expand Up @@ -1379,6 +1379,7 @@ def generated_species_constraints(**kwargs):
'maximumRadicalElectrons',
'maximumSingletCarbenes',
'maximumCarbeneRadicals',
'maximumFusedRings',
'allowSingletO2',
'speciesCuttingThreshold',
]
Expand Down
1 change: 0 additions & 1 deletion scripts/rmg2to3.py
Expand Up @@ -1796,7 +1796,6 @@
# rmgpy.tools.isotopes
'useOriginalReactions': 'use_original_reactions',
'kineticIsotopeEffect': 'kinetic_isotope_effect',
'maximumIsotopicAtoms': 'maximum_isotopic_atoms',
# rmgpy.tools.loader
'generateImages': 'generate_images',
'useJava': 'use_java',
Expand Down
11 changes: 11 additions & 0 deletions test/rmgpy/molecule/moleculeTest.py
Expand Up @@ -2956,3 +2956,14 @@ def test_remove_van_der_waals_bonds(self):
assert len(mol.get_all_edges()) == 2
mol.remove_van_der_waals_bonds()
assert len(mol.get_all_edges()) == 1

def test_get_ring_count_in_largest_fused_ring_system(self):
"""Test that we can count the rings in the largest fused ring system."""
mol = Molecule(smiles="CCCC")
assert mol.get_ring_count_in_largest_fused_ring_system() == 0
mol = Molecule(smiles="c1ccccc1")
assert mol.get_ring_count_in_largest_fused_ring_system() == 0
mol = Molecule(smiles="c12ccccc1cccc2")
assert mol.get_ring_count_in_largest_fused_ring_system() == 2
mol = Molecule(smiles="C[C]1C2C(=O)C3CC4C(=O)C=C2CC143")
assert mol.get_ring_count_in_largest_fused_ring_system() == 4