Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 0.14.0.0 #25

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.npy
*.jpg
*.ply
*.png
*.txt
133 changes: 133 additions & 0 deletions examples/blender_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
from pyqint import Molecule, PyQInt, FosterBoys, GeometryOptimization, HF
from pyqint import MoleculeBuilder, BlenderRender
import pyqint
import numpy as np
import matplotlib.pyplot as plt
import os
import subprocess

#
# 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.
#

outpath = os.path.dirname(__file__)

def main():
build_orbitals_co()
build_orbitals_ch4()
build_orbitals_ethylene()

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_orbitals_ethylene():
"""
Build a montage image of the canonical and localized molecular orbitals
of CH4
"""
molname = 'ethylene'
mol = MoleculeBuilder().from_name('ethylene')
res = GeometryOptimization().run(mol, 'sto3g')['data']
resfb = FosterBoys(res).run()

build(molname, res, resfb, nrows=2)

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'], 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()
2 changes: 2 additions & 0 deletions examples/foster_boys.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def optimize_co():

res = GeometryOptimization().run(mol, 'sto3g')

print(res['data']['nuclei'])

return res['data']

def build_contourplot(cgfs, coeff, sz=2, npts=50, plane='xy'):
Expand Down
2 changes: 1 addition & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: "pyqint"
version: "0.13.1.0"
version: "0.14.0.0"

source:
path: .
Expand Down
2 changes: 1 addition & 1 deletion pyqint/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.13.1.0"
__version__ = "0.14.0.0"

3 changes: 3 additions & 0 deletions pyqint/blender/blender_render_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ def set_environment(settings):
Specify canvas size, remove default objects, reset positions of
camera and light, define film and set background
"""
print('Set render engine to: CYCLES')
bpy.context.scene.render.engine = 'CYCLES'
print('Set rendering device to GPU')
bpy.context.scene.cycles.device = 'GPU'
bpy.context.scene.render.resolution_x = settings['resolution']
bpy.context.scene.render.resolution_y = settings['resolution']
print('Setting resolution to: ', settings['resolution'])
bpy.context.scene.cycles.samples = 1024
bpy.context.scene.cycles.tile_size = 2048

Expand Down
Loading