In [1]:
from rmgpy.molecule.resonance import *
from rmgpy.molecule.molecule import Molecule

import sys, time
import cProfile

In [2]:
molList = [
    'CC', 'CCC', 'CCCC',
    'C=C[CH2]', 'CC=C[CH2]', 'C=CC=C[CH2]', 'C=C[CH]C=CC',
    'CC=N[O]', 'CCN=N=[N-]',
    'c1ccccc1', 'c1ccccc1C', 
    'c1ccccc1[CH2]', 'c1ccccc1[C]=C', 'c1ccccc1[CH2]C', 'C1ccccc1[CH2]C=C',
    'C1=CC=C(C=C1)C1C=CC=CC=1',
    'C1=CC=C2C=CC=CC2=C1',
    'C1=CC2=CC=CC3C=CC(=C1)C=32',
    'C1=CC=C2C=C3C=CC=CC3=CC2=C1',
    'C1=CC=C2C(C=CC3=CC=CC=C32)=C1',
    'C1=CC2=CC=CC3CC=CC(=C1)C=32',
    'C1=CC=C2C=C3C=C4C=CC=CC4=CC3=CC2=C1',
    'C1=CC=C2C(C=CC3C2=CC=C2C=CC=CC=32)=C1',
    'C1=CC=C2C(=C1)C1=CC=CC=C1C1=CC=CC=C21',
    'C1=CC2=CC=C3C=CC=C4C=CC(=C1)C2=C43',
    'C1=CC=C2C=C3C(C=CC4=CC=CC=C43)=CC2=C1',
    'C1=CC=C2C=C3C=C4C=C5C=CC=CC5=CC4=CC3=CC2=C1',
    'C1=CC=C2C(=C1)C=C1C=CC3=CC=CC4=CC=C2C1=C34',
    'C1=CC2=CC=C3C=CC4=C5C6=C(C2=C35)C1=CC=C6C=C4',
    'C1=CC2=CC=CC3C4=CC=CC5=CC=CC(C(=C1)C=32)=C54',
    'C1=CC2=CC=C3C=C4C=CC=C5C=CC6=CC(=C1)C2=C3C6=C54',
    'C1=CC2=CC=C3C=CC4=CC=C5C=CC=C6C(=C1)C2=C3C4=C56',
    'C1=CC=C2C(=C1)C=C1C3=CC=CC=C3C3=CC=CC4=CC=C2C1=C43',
    'C1=CC2=CC=C3C=CC4=CC=C5C=CC6=CC=C1C1=C2C3=C4C5=C61',
    'C1=CC2=CC=C3C=C4C=CC5=CC=C6C=CC7=CC8=CC=C1C1=C2C3=C2C4=C5C6=C7C2=C81',
]

In [3]:
for mol in molList:
    molecule = Molecule().fromSMILES(mol)
    newmol = generateResonanceIsomers(molecule)

In [3]:
script = """\
for mol in molList:
    molecule = Molecule().fromSMILES(mol)
    newmol = generateResonanceIsomers(molecule)
"""

cProfile.run(script)


         10671 function calls (10419 primitive calls) in 2.244 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    2.244    2.244 <string>:1(<module>)
        2    0.000    0.000    0.000    0.000 __init__.py:23(find_module)
      350    0.001    0.000    0.001    0.000 iostream.py:304(fileno)
       35    0.000    0.000    0.053    0.002 openbabel.py:1689(__init__)
       35    0.000    0.000    0.000    0.000 openbabel.py:2270(__init__)
       35    0.000    0.000    0.000    0.000 openbabel.py:3764(__init__)
      822    0.000    0.000    0.000    0.000 openbabel.py:3767(__nonzero__)
       35    0.000    0.000    0.000    0.000 openbabel.py:4351(__init__)
      885    0.000    0.000    0.000    0.000 openbabel.py:4354(__nonzero__)
       70    0.000    0.000    0.001    0.000 openbabel.py:5008(__init__)
       70    0.000    0.000    0.000    0.000 openbabel.py:5014(__iter__)
     1707    0.004    0.000    0.006    0.000 openbabel.py:5020(next)
       35    0.045    0.001    2.137    0.061 resonance.py:129(generateResonanceIsomers)
       19    0.001    0.000    0.001    0.000 resonance.py:166(generateAdjacentResonanceIsomers)
        6    0.000    0.000    0.000    0.000 resonance.py:209(generateLonePairRadicalResonanceIsomers)
        6    0.000    0.000    0.000    0.000 resonance.py:256(generateN5dd_N5tsResonanceIsomers)
      112    0.425    0.004    0.425    0.004 resonance.py:339(generateAromaticResonanceIsomers)
      130    0.120    0.001    0.120    0.001 resonance.py:398(generateKekulizedResonanceIsomers)
       98    0.003    0.000    1.463    0.015 resonance.py:469(generateClarStructures)
   350/98    1.412    0.004    1.413    0.014 resonance.py:515(clarOptimization)
       35    0.000    0.000    0.000    0.000 resonance.py:58(populateResonanceAlgorithms)
      460    0.046    0.000    0.046    0.000 resonance.py:625(clarTransformation)
       35    0.082    0.002    0.082    0.002 resonance.py:92(analyzeMolecule)
        4    0.000    0.000    0.000    0.000 six.py:184(find_module)
       35    0.000    0.000    0.000    0.000 {_openbabel.OBConversion_swiginit}
       35    0.000    0.000    0.000    0.000 {_openbabel.OBMol_swiginit}
      822    0.000    0.000    0.000    0.000 {_openbabel._OBMolAtomIter___nonzero__}
      787    0.000    0.000    0.000    0.000 {_openbabel._OBMolAtomIter___ref__}
      787    0.001    0.000    0.001    0.000 {_openbabel._OBMolAtomIter_inc}
       35    0.000    0.000    0.000    0.000 {_openbabel._OBMolAtomIter_swiginit}
      885    0.000    0.000    0.000    0.000 {_openbabel._OBMolBondIter___nonzero__}
      850    0.000    0.000    0.000    0.000 {_openbabel._OBMolBondIter___ref__}
      850    0.000    0.000    0.000    0.000 {_openbabel._OBMolBondIter_inc}
       35    0.000    0.000    0.000    0.000 {_openbabel._OBMolBondIter_swiginit}
       35    0.052    0.001    0.052    0.001 {_openbabel.new_OBConversion}
       35    0.000    0.000    0.000    0.000 {_openbabel.new_OBMol}
       35    0.000    0.000    0.000    0.000 {_openbabel.new__OBMolAtomIter}
       35    0.000    0.000    0.000    0.000 {_openbabel.new__OBMolBondIter}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
       35    0.047    0.001    0.107    0.003 {method 'fromSMILES' of 'rmgpy.molecule.molecule.Molecule' objects}
        2    0.000    0.000    0.000    0.000 {method 'partition' of 'str' objects}
       35    0.000    0.000    2.137    0.061 {rmgpy.molecule.resonance.generateResonanceIsomers}



In [ ]:
times = []
output = []

for mol in molList:
    molecule = Molecule().fromSMILES(mol)
    try:
        t0 = time.time()
        newmol = generateResonanceIsomers(molecule)
        t1 = time.time()
        output.append(newmol)
    except:
        output.append(sys.exc_info()[0])
    times.append(t1 - t0)

In [ ]:
times

In [ ]:
import numpy as np
print np.mean(times), np.sum(times)

In [ ]:
output

In [ ]:
a = [(0.00892686843872, 0.312440395355), (0.00796243803842, 0.278685331345)]
b = [(0.0490251541138, 1.71588039398), (0.0532118047987, 1.86241316795)]
c = [(0.0546148300171, 1.9115190506),(0.0541006292616, 1.89352202415)]

In [ ]:


In [ ]: