Skip to content

Commit bd8f7c3

Browse files
committed
build an rmgmolecule package in place, fix conda builds
- small updates to rmg-py recipe - removed conda_build.yml action since it will now be done in a private repo - added a recipe for rmgmolecule - add warnings on molecule when running from rmgmolecule that some functionality is not available
1 parent 87b96e1 commit bd8f7c3

File tree

9 files changed

+261
-66
lines changed

9 files changed

+261
-66
lines changed

.conda/meta.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111

1212
requirements:
1313
build:
14-
- {{ compiler('c') }} # [unix]
14+
- {{ compiler('c') }}
1515
host:
1616
- cython >=0.25.2
1717
- lpsolve55
@@ -78,10 +78,8 @@ test:
7878
- rmgpy
7979
- arkane
8080
commands:
81-
- rmg.py examples/rmg/superminimal/input.py # [unix]
82-
- Arkane.py examples/arkane/networks/n-butanol/input.py # [unix]
83-
- python %SCRIPTS%\rmg.py examples\rmg\superminimal\input.py # [win]
84-
- python %SCRIPTS\Arkane.py examples\arkane\networks\n-butanol\input.py # [win]
81+
- python-jl rmg.py examples/rmg/superminimal/input.py
82+
- python arkane.py examples/arkane/networks/n-butanol
8583

8684
about:
8785
home: https://github.com/ReactionMechanismGenerator/RMG-Py

.github/workflows/conda_build.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

.rmgmolecule_conda/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Install rmgmolecule
2+
python rmgmolecule_setup.py install
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
numpy:
2+
- 1.19

.rmgmolecule_conda/meta.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# meta.yaml - package specification for rmgmolecule subpackage
2+
package:
3+
name: rmgmolecule
4+
version: 1.0.0
5+
6+
source:
7+
path: ../
8+
9+
build:
10+
number: {{ environ.get('GIT_DESCRIBE_NUMBER', 0) }}
11+
12+
requirements:
13+
build:
14+
- {{ compiler('c') }} # [unix]
15+
host:
16+
- cython >=0.25.2
17+
- lpsolve55
18+
- numpy
19+
- openbabel >=3
20+
- pyrdl
21+
- python==3.7
22+
- quantities
23+
- rdkit >=2018
24+
- scipy
25+
- scikit-learn
26+
- setuptools
27+
run:
28+
- cairo
29+
- cairocffi
30+
- cython >=0.25.2
31+
- gprof2dot
32+
- graphviz
33+
- jinja2
34+
- jupyter
35+
- lpsolve55
36+
- {{ pin_compatible('numpy') }}
37+
- openbabel >=3
38+
- pydot
39+
- pyrdl
40+
- python==3.7
41+
- quantities
42+
- rdkit >=2018
43+
- scikit-learn
44+
test:
45+
imports:
46+
- rmgpy.molecule
47+
commands:
48+
- python -c 'from rmgpy.molecule import Molecule; mol=Molecule().from_smiles("CC")'
49+
50+
about:
51+
home: https://github.com/ReactionMechanismGenerator/RMG-Py
52+
license: MIT
53+
summary: "The ReactionMechanismGenerator Molecule Subpackage"

rmgmolecule_setup.py

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
import sys
2+
import os
3+
from collections import OrderedDict
4+
5+
try:
6+
from distutils.core import setup
7+
from distutils.extension import Extension
8+
except ImportError:
9+
print("The distutils package is required to build or install RMG Py.")
10+
raise
11+
12+
try:
13+
from Cython.Build import cythonize
14+
from Cython.Compiler import Options
15+
except ImportError:
16+
print("Cython (http://www.cython.org/) is required to build or install RMG Py.")
17+
raise
18+
19+
try:
20+
import numpy
21+
except ImportError:
22+
print("NumPy (http://numpy.scipy.org/) is required to build or install RMG Py.")
23+
raise
24+
25+
# Create annotated HTML files for each of the Cython modules
26+
Options.annotate = True
27+
28+
directives = {
29+
# Set input language version to python 3
30+
"language_level": 3,
31+
# Turn on profiling capacity for all Cython modules
32+
# 'profile': True,
33+
# Embed call signatures in cythonized files - enable when building documentation
34+
# 'embedsignature': True,
35+
}
36+
37+
38+
main_ext_modules = [
39+
# Molecules and molecular representations
40+
Extension(
41+
"rmgpy.molecule.atomtype",
42+
["rmgpy/molecule/atomtype.py"],
43+
include_dirs=["."],
44+
),
45+
Extension(
46+
"rmgpy.molecule.element",
47+
["rmgpy/molecule/element.py"],
48+
include_dirs=["."],
49+
),
50+
Extension(
51+
"rmgpy.molecule.graph",
52+
["rmgpy/molecule/graph.pyx"],
53+
include_dirs=["."],
54+
),
55+
Extension(
56+
"rmgpy.molecule.group",
57+
["rmgpy/molecule/group.py"],
58+
include_dirs=["."],
59+
),
60+
Extension(
61+
"rmgpy.molecule.molecule",
62+
["rmgpy/molecule/molecule.py"],
63+
include_dirs=["."],
64+
),
65+
Extension(
66+
"rmgpy.molecule.symmetry",
67+
["rmgpy/molecule/symmetry.py"],
68+
include_dirs=["."],
69+
),
70+
Extension(
71+
"rmgpy.molecule.vf2",
72+
["rmgpy/molecule/vf2.pyx"],
73+
include_dirs=["."],
74+
),
75+
Extension(
76+
"rmgpy.molecule.converter",
77+
["rmgpy/molecule/converter.py"],
78+
include_dirs=["."],
79+
),
80+
Extension(
81+
"rmgpy.molecule.translator",
82+
["rmgpy/molecule/translator.py"],
83+
include_dirs=["."],
84+
),
85+
Extension(
86+
"rmgpy.molecule.util",
87+
["rmgpy/molecule/util.py"],
88+
include_dirs=["."],
89+
),
90+
Extension(
91+
"rmgpy.molecule.inchi",
92+
["rmgpy/molecule/inchi.py"],
93+
include_dirs=["."],
94+
),
95+
Extension(
96+
"rmgpy.molecule.resonance",
97+
["rmgpy/molecule/resonance.py"],
98+
include_dirs=["."],
99+
),
100+
Extension(
101+
"rmgpy.molecule.pathfinder",
102+
["rmgpy/molecule/pathfinder.py"],
103+
include_dirs=["."],
104+
),
105+
Extension(
106+
"rmgpy.molecule.kekulize",
107+
["rmgpy/molecule/kekulize.pyx"],
108+
include_dirs=["."],
109+
),
110+
Extension(
111+
"rmgpy.constants",
112+
["rmgpy/constants.py"],
113+
include_dirs=["."],
114+
),
115+
Extension(
116+
"rmgpy.quantity",
117+
["rmgpy/quantity.py"],
118+
include_dirs=["."],
119+
),
120+
Extension(
121+
"rmgpy.rmgobject",
122+
["rmgpy/rmgobject.pyx"],
123+
),
124+
]
125+
126+
ext_modules = []
127+
if "install" in sys.argv:
128+
# This is so users can still do simply `python setup.py install`
129+
ext_modules.extend(main_ext_modules)
130+
if "main" in sys.argv:
131+
# This is for `python setup.py build_ext main`
132+
sys.argv.remove("main")
133+
ext_modules.extend(main_ext_modules)
134+
if "minimal" in sys.argv:
135+
# This starts with the full install list, but removes anything that has a pure python mode
136+
# i.e. in only includes things whose source is .pyx
137+
sys.argv.remove("minimal")
138+
temporary_list = []
139+
temporary_list.extend(main_ext_modules)
140+
for module in temporary_list:
141+
for source in module.sources:
142+
if os.path.splitext(source)[1] == ".pyx":
143+
ext_modules.append(module)
144+
145+
# Remove duplicates while preserving order:
146+
ext_modules = list(OrderedDict.fromkeys(ext_modules))
147+
148+
scripts = []
149+
150+
modules = ["rmgpy.exceptions", "rmgpy.version"]
151+
152+
__version__ = "1.0.0"
153+
154+
import logging
155+
156+
logging.error(ext_modules)
157+
# Initiate the build and/or installation
158+
setup(
159+
name="RMG-Py",
160+
version=__version__,
161+
description="Reaction Mechanism Generator",
162+
author="William H. Green and the RMG Team",
163+
author_email="[email protected]",
164+
url="http://reactionmechanismgenerator.github.io",
165+
packages=[
166+
"rmgpy.molecule",
167+
],
168+
py_modules=modules,
169+
scripts=scripts,
170+
ext_modules=cythonize(
171+
ext_modules,
172+
build_dir="build",
173+
compiler_directives=directives,
174+
),
175+
include_dirs=[".", numpy.get_include()],
176+
)

rmgpy/molecule/draw.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@
6161
from rdkit.Chem import AllChem
6262

6363
from rmgpy.molecule.molecule import Atom, Molecule
64-
from rmgpy.qm.molecule import Geometry
64+
65+
Geometry = None
66+
try:
67+
from rmgpy.qm.molecule import Geometry
68+
except ImportError:
69+
logging.info("Unable to import Geometry rmgpy.qm.molecule - feature disabled.")
6570

6671

6772
################################################################################
@@ -437,6 +442,11 @@ def _generate_coordinates(self):
437442
# Generate the RDkit molecule from the RDkit molecule, use geometry
438443
# in order to match the atoms in the rdmol with the atoms in the
439444
# RMG molecule (which is required to extract coordinates).
445+
if Geometry is None:
446+
raise RuntimeError("""
447+
Missing rmgpy.qm.molecule.Geometry required for 2D coordinate generation.
448+
Please install the full version of RMG to use this function.
449+
""")
440450
self.geometry = Geometry(None, None, self.molecule, None)
441451

442452
rdmol, rd_atom_idx = self.geometry.rd_build()

rmgpy/molecule/fragment.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,13 @@ def assign_representative_molecule(self):
10201020

10211021
def assign_representative_species(self):
10221022

1023-
from rmgpy.species import Species
1023+
try:
1024+
from rmgpy.species import Species
1025+
except ImportError as ie:
1026+
raise RuntimeError(
1027+
"Cannot call Fragment.assign_representative_species() in rmgmolecule installation."
1028+
" Please install the full version of RMG."
1029+
) from ie
10241030
self.assign_representative_molecule()
10251031
self.species_repr = Species(molecule=[self.mol_repr])
10261032
self.symmetry_number = self.get_symmetry_number()

rmgpy/molecule/inchi.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,13 @@ def _convert_3_atom_2_bond_path(start, mol):
702702
with a number of actions that reflect the changes in bond orders and unpaired
703703
electrons that the molecule should undergo.
704704
"""
705-
from rmgpy.data.kinetics.family import ReactionRecipe
705+
try:
706+
from rmgpy.data.kinetics.family import ReactionRecipe
707+
except ImportError as ie:
708+
raise RuntimeError(
709+
"Cannot call inchi._convert_3_atom_2_bond_path() in rmgmolecule installation."
710+
" Please install the full version of RMG."
711+
) from ie
706712

707713
def is_valid(mol):
708714
"""Check if total bond order of oxygen atoms is smaller than 4."""

0 commit comments

Comments
 (0)