Created
October 9, 2018 17:48
-
-
Save ghutchis/4b52ef8ccd97270d120e1ef1b54144af to your computer and use it in GitHub Desktop.
Calculation dipole moments using Open Babel in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import sys | |
import os | |
import math | |
import pybel | |
# You can get a list of charge models | |
# using `obabel -L charges` | |
methods = [ 'mmff94', 'gasteiger', 'eem2015bm' ] | |
for argument in sys.argv[1:]: | |
filename, extension = os.path.splitext(argument) | |
# read the molecule from the supplied file | |
for mol in pybel.readfile(extension[1:], argument): | |
for method in methods: | |
# on the command-line, you can get partial charges like this | |
# obabel CHF3.g03 -onul --partialcharge gasteiger --print | |
cm = ob.OBChargeModel_FindType(method) | |
cm.ComputeCharges(mol.OBMol) | |
# but in C++ or Python we can get the dipole moment vector | |
dipole = cm.GetDipoleMoment(mol.OBMol) | |
moment = math.sqrt(dipole.GetX()**2+dipole.GetY()**2+dipole.GetZ()**2) | |
print(filename, method, moment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment