Running multiple calculations can be useful when many results are needed. An example is given below.
In [ ]:
import openchemistry as oc
import matplotlib.pyplot as plt
Start by creating a list of SMILES to perform the calculations on. Note that generating 3D structure is optional, and can be skipped for batch calculations such as these.
In [ ]:
structure_smiles = ['CN1CNCN(C1)c1ccc(c2c1cccc2)C1NCNCN1', 'SC1CSCC(S1)(S)c1cccnc1', 'c1ccc(nc1)c1scc(c1)c1ccnc(c1)c1ccc2c(c1)cccc2']
mols = []
for smiles in structure_smiles:
mols.append(oc.import_structure(smiles, gen3d=False))
When viewing a molecule that does not have 3D structure, a 2D SVG will be displayed.
In [ ]:
mols[0].structure.show()
Multiple calculations can be ran in a single docker container if they are submitted using oc.run_calculations()
In [ ]:
image_name = 'openchemistry/chemml:0.6.0'
input_parameters = {}
In [ ]:
results = oc.run_calculations(mols, image_name, input_parameters)
All of the calculations will finish simultaneously, and their status may be tracked by requesting one of their outputs:
In [ ]:
results[0].properties.show()
Once the calculations are finished, their results can be obtained and plotted.
In [ ]:
x = []
y = []
for result in results:
x.append(result.data()['properties']['polarizability'])
y.append(result.data()['properties']['refractiveIndex'])
In [ ]:
fig, ax = plt.subplots()
ax.plot(x, y, 'ro')
ax.set(xlabel='polarizability', ylabel='refractive index', title='Machine learning...')
ax.grid()
If a 3D calculation is attempted on a 2D molecule, 3D coordinate generation will automatically start, and a message will alert the user to try again soon.
In [ ]:
image_name = 'openchemistry/psi4:1.2.1'
input_parameters = {
'theory': 'dft',
'functional': 'b3lyp',
'basis': '6-31g'
}
In [ ]:
result = mols[0].energy(image_name, input_parameters)
In [ ]:
result.orbitals.show(mo='homo', iso=0.005)
Alternatively, 3D coordinates may also be generated manually. If this is done, the forcefield options may also be passed.
In [ ]:
mols[1].structure.generate_3d(forcefield='uff', steps=150)
For typed calculations, the type can be specified by adding the appropriate "task" keyword to the input parameters.
In [ ]:
input_parameters['task'] = 'energy'
results = oc.run_calculations(mols, image_name, input_parameters)
In [ ]:
results[0].orbitals.show(mo='homo', iso=0.005)