Quantum chemistry calculation with python.

In this weekend, I played molecular design toolkit.
https://bionano.autodesk.com/MolecularDesignToolkit/
This is very nice open source tool kit for pythonist I think. At first, I tried to install the TK in OSx directly, but I had some trouble to run the code. So I installed my linux virtual PC. It is not so difficult to install molecular design TK in linux environment.
At frist mdt can install by using pip.

pip install moldesign

Easy!
And next, I installed some packages by using conda.
I recommend to install pyscf ( quantum chemistry package for python ) by using conda. Because I had some troubles when I build pyscf from source code.

conda install -c moldesign nbmolviz 
conda install -c conda-forge widgetsnbextension
conda install -c pyqc pyscf 
conda install -c omnia openmm
conda install -c omnia pdbfixer 

And also I installed openbabel by apt-get.

apt-get install openbabel python-openbabel

OK, Now ready!
Let’s start coding.
Today, I tried to simple example.
Read string, generate 3D, calculate orbitals and visualize it.
Following code is running on jupyter notebook. 😉

import moldesign as mdt
import moldesign.units as u
import pybel
# read molecule from smiles and generate 3D conf and save sdf.
mol = pybel.readstring( "smi","C1=NC2=C(N1)C(=NC=N2)N" )
mol.addh()
mol.make3D()
mol.write("sdf",'adenine.sdf')

Read and draw

mol=mdt.read("adenine.sdf")
mol.draw()


Draw function draws 2D and 3D structure.

Next, calculate energy and draw molecular orbital.

mol.set_energy_model( mdt.models.RHF, basis='sto-3g')
prop = mol.calculate()
print( prop.keys() )
print( "Energy: ", prop['potential_energy'])
['positions', 'mulliken', 'wfn', 'potential_energy', 'dipole_moment']
('Energy: ', <Quantity(-12479.0741253, 'eV')>)
mol.draw_orbitals()


Works fine. draw_orbitals() can draw some orbitals like HOMO, LUMO, and any other energy level orbitals.

Finally, minimize it.
And draw orbitals.

mintraj = mol.minimize()

Starting geometry optimization: built-in gradient descent
Starting geometry optimization: SciPy/bfgs with analytical gradients
Step 2/20, ΔE=-1.858e-01 eV, RMS ∇E=4.161e-01, max ∇E=1.305e+00 eV / ang
Step 4/20, ΔE=-2.445e-01 eV, RMS ∇E=1.818e-01, max ∇E=6.069e-01 eV / ang
Step 6/20, ΔE=-2.589e-01 eV, RMS ∇E=1.359e-01, max ∇E=4.905e-01 eV / ang
Step 8/20, ΔE=-2.620e-01 eV, RMS ∇E=1.250e-01, max ∇E=5.032e-01 eV / ang
Step 10/20, ΔE=-2.660e-01 eV, RMS ∇E=1.264e-01, max ∇E=3.384e-01 eV / ang
Step 12/20, ΔE=-2.751e-01 eV, RMS ∇E=1.125e-01, max ∇E=2.966e-01 eV / ang
Step 14/20, ΔE=-2.915e-01 eV, RMS ∇E=2.315e-01, max ∇E=5.801e-01 eV / ang
Step 16/20, ΔE=-2.942e-01 eV, RMS ∇E=2.492e-01, max ∇E=6.325e-01 eV / ang
Step 18/20, ΔE=-2.978e-01 eV, RMS ∇E=2.712e-01, max ∇E=7.771e-01 eV / ang
Step 20/20, ΔE=-3.016e-01 eV, RMS ∇E=2.639e-01, max ∇E=7.127e-01 eV / ang
Warning: Maximum number of iterations has been exceeded.
         Current function value: -12479.375700
         Iterations: 19
         Function evaluations: 26
         Gradient evaluations: 26
Reduced energy from -12479.0741253 eV to -12479.3757001 eV
mintraj.draw_orbitals()


mintraj object has each steps energy state. And it can be shown as movie.

Also lots of functions are implemented in molecular design tool kit.
I will play with package more and more. 😉
Today’s code was pushed my repository.
https://github.com/iwatobipen/moldesigntk/blob/master/test1.ipynb

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s