-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,120 @@ | ||
from pyqint import Molecule, PyQInt, FosterBoys, GeometryOptimization, HF | ||
from pyqint import BlenderRender | ||
from pyqint import MoleculeBuilder, BlenderRender | ||
import pyqint | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import os | ||
import subprocess | ||
|
||
# | ||
# Plot the isosurfaces for the CO molecule | ||
# Plot the isosurfaces for a number of molecules, prior and after | ||
# orbital localization. Note that this script has been designed to be executed | ||
# in a Linux Ubuntu 22.04 LTS (WSL) container. | ||
# | ||
|
||
print(pyqint.__version__) | ||
outpath = os.path.dirname(__file__) | ||
|
||
def main(): | ||
def main(): | ||
# build_orbitals_co() | ||
build_orbitals_ch4() | ||
|
||
def build_orbitals_co(): | ||
""" | ||
Build a montage image of the canonical and localized molecular orbitals | ||
of CO | ||
""" | ||
molname = 'CO' | ||
mol = Molecule('CO') | ||
mol.add_atom('C', 0, 0, -1.08232106) | ||
mol.add_atom('O', 0, 0, 1.08232106) | ||
res = HF().rhf(mol, 'sto3g') | ||
resfb = FosterBoys(res).run() | ||
|
||
build(molname, res, resfb, nrows=2) | ||
|
||
def build_orbitals_ch4(): | ||
""" | ||
Build a montage image of the canonical and localized molecular orbitals | ||
of CH4 | ||
""" | ||
molname = 'CH4' | ||
mol = MoleculeBuilder().from_name('ch4') | ||
res = GeometryOptimization().run(mol, 'sto3g')['data'] | ||
resfb = FosterBoys(res).run() | ||
|
||
build(molname, res, resfb, nrows=3) | ||
|
||
def build(molname, res, resfb, nrows=2): | ||
""" | ||
Build isosurfaces, montage and print energies to a file | ||
:param molname: Name of the molecule | ||
:type molname: string | ||
:param res: Results of a Hartree-Fock calculation | ||
:type res: dictionary | ||
:param resfb: Results of a Foster-Boys localization | ||
:type resfb: dictionary | ||
:param nrows: Number of rows in the montage | ||
:type nrows: int | ||
""" | ||
#build_isosurfaces(molname, res, resfb) | ||
montage(molname, nrows) | ||
store_energies(os.path.join(os.path.dirname(__file__), 'MO_%s_energies.txt' % molname), res['orbe'], resfb['orbe']) | ||
|
||
def build_isosurfaces(molname, res, resfb): | ||
""" | ||
Builds isosurfaces. | ||
:param molname: Name of the molecule | ||
:type molname: string | ||
:param res: Result of a Hartree-Fock calculation | ||
:type res: dictionary | ||
:param resfb: Result of a Foster-Boys localization | ||
:type resfb: dictionary | ||
""" | ||
br = BlenderRender() | ||
br.render_molecular_orbitals(res['mol'], res['cgfs'], resfb['orbc'], outpath) | ||
br.render_molecular_orbitals(res['mol'], res['cgfs'], res['orbc'], outpath, | ||
prefix='MO_CAN_%s' % molname) | ||
|
||
br.render_molecular_orbitals(resfb['mol'], res['cgfs'], resfb['orbc'], outpath, | ||
prefix='MO_FB_%s' % molname) | ||
|
||
def montage(molname, nrows=2): | ||
""" | ||
Produce a montage of the images | ||
:param molname: Name of the molecule | ||
:type molname: string | ||
:param nrows: Number of rows in the montage | ||
:type nrows: int | ||
""" | ||
out = subprocess.check_output( | ||
['montage', 'MO_CAN_%s_????.png' % molname, '-tile', 'x%i' % nrows, '-geometry', '128x128+2+2', 'MO_%s_CAN.png' % molname], | ||
cwd=os.path.dirname(__file__) | ||
) | ||
|
||
out = subprocess.check_output( | ||
['montage', 'MO_FB_%s_????.png' % molname, '-tile', 'x%i' % nrows, '-geometry', '128x128+2+2', 'MO_%s_FB.png' % molname], | ||
cwd=os.path.dirname(__file__) | ||
) | ||
|
||
def store_energies(filename, orbe, orbe_fb): | ||
""" | ||
Stores energies. | ||
:param filename: Name of the molecule | ||
:type filename: string | ||
:param orbe: Array of the canonical molecular orbital energies | ||
:type orbe: list or numpy array | ||
:param orbe_fb: Array of the localized molecular orbital energies | ||
:type orbe_fb: list or numpy array | ||
""" | ||
f = open(filename, 'w') | ||
f.write('id localized canonical\n') | ||
f.write('----------------------------\n') | ||
for i in range(len(orbe)): | ||
f.write("%02i %12.4f %12.4f\n" % (i+1, orbe[i], orbe_fb[i])) | ||
f.close() | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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