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

Bug fixes for vtools and updates for notebook file #8

Merged
merged 4 commits into from Nov 27, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
116 changes: 83 additions & 33 deletions valence_tutorial.ipynb
@@ -1,10 +1,39 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Installation\n",
"You can create a conda environment to install all the dependencies:\n",
"```\n",
"conda env create -f environment.yml\n",
"```\n",
"After conda creates the environment, you can activate it with\n",
"```\n",
"conda activate valence-env\n",
"```\n",
"You can add valence-env as a Jupyter kernel:\n",
"```\n",
"python -m ipykernel install --user --name valence-env\n",
"```\n",
"After this step, valence-env should be available in Jupyter Notebook Kernel/Change Kernel menu."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 62,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
Expand All @@ -16,27 +45,30 @@
"#import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from subprocess import Popen\n",
"from ipywidgets import interact, interactive, fixed, interact_manual, Textarea, widgets, Layout,VBox,HBox, Box,Text\n",
"from ipywidgets import interact, interactive\n",
"from ipywidgets import fixed, interact_manual \n",
"from ipywidgets import Textarea, widgets, Layout, Accordion\n",
"from ipywidgets import VBox, HBox, Box, Text, BoundedIntText\n",
"import numpy as np\n",
"%matplotlib inline\n"
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 61,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "495c5cd48c4347d49666f26bf447dba1",
"model_id": "d8f38fa84bbf4fef80f2536d2cdb133f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"aW50ZXJhY3RpdmUoY2hpbGRyZW49KFRleHQodmFsdWU9dSdDJywgZGVzY3JpcHRpb249dSdtb2wnKSwgRHJvcGRvd24oZGVzY3JpcHRpb249dSdzdHlsZScsIGluZGV4PTMsIG9wdGlvbnM9KCfigKY=\n"
"aW50ZXJhY3RpdmUoY2hpbGRyZW49KFRleHRhcmVhKHZhbHVlPXUnTycsIGRlc2NyaXB0aW9uPXUnbW9sJywgbGF5b3V0PUxheW91dChoZWlnaHQ9dScxMDBweCcsIHdpZHRoPXUnNDAwcHgnKSnigKY=\n"
]
},
"metadata": {},
Expand All @@ -50,69 +82,87 @@
" #http://3dmol.csb.pitt.edu/doc/types.html#AtomStyleSpec\n",
" mol = ob.get_mol((mol),make3D=True)\n",
" xyz = ob.get_xyz(mol)\n",
" xyzview = py3Dmol.view(width=400,height=400)\n",
" xyzview = py3Dmol.view(width=200,height=200)\n",
" xyzview.addModel(xyz,'xyz')\n",
" xyzview.setStyle({style:{'radius':radius}})\n",
" xyzview.setBackgroundColor('0xeeeeee')\n",
" xyzview.animate({'loop': 'backAndForth'})\n",
" xyzview.zoomTo()\n",
" xyzview.show()\n",
" xyztext = Textarea(value=xyz,layout={'height': '200px','width':'600px'})\n",
" xyztext = Textarea(value=xyz,layout={'height': '200px','width':'400px'})\n",
" display(xyztext)\n",
" return"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": true
},
"execution_count": 75,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "768181422b364d5faef81bf95488d294",
"model_id": "1f371f4b98464fabaa5b2f78de9e6aea",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"aW50ZXJhY3RpdmUoY2hpbGRyZW49KFRleHRhcmVhKHZhbHVlPXUnTycsIGRlc2NyaXB0aW9uPXUnbW9sJywgbGF5b3V0PUxheW91dChoZWlnaHQ9dScxMDBweCcsIHdpZHRoPXUnNDAwcHgnKSnigKY=\n"
"aW50ZXJhY3RpdmUoY2hpbGRyZW49KFRleHRhcmVhKHZhbHVlPXUnTycsIGRlc2NyaXB0aW9uPXUnaWRlbnRpZmllcicsIGxheW91dD1MYXlvdXQoaGVpZ2h0PXUnNTBweCcsIHdpZHRoPXUnMzDigKY=\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"@interact(mol=Textarea(value='O',layout={'height': '100px','width':'400px'}),basis='vtools/631g',fullbasis=False, allatoms=False)\n",
"def interactive_input_generator(mol,basis,fullbasis=False, allatoms=False):\n",
"@interact(mol=Textarea(value='O',layout={'height': '50px','width':'300px'},description='identifier'),\n",
" basis='vtools/631g',niter=BoundedIntText(min=0,value=1,description='Niter'),\n",
" optimization=['very tight','tight','default','coarse','very coarse'],fullbasis=False, allatoms=False)\n",
"def interactive_input_generator(mol,basis, niter=1, optimization='default',fullbasis=False, allatoms=False):\n",
" mol = ob.get_mol(mol,make3D=True)\n",
" print('Molecular formula: {}'.format(ob.get_formula(mol)))\n",
" print('Multiplicity: {}'.format(ob.get_multiplicity(mol)))\n",
" print('Number of electrons: {}'.format(ob.get_nelectron(mol)))\n",
" print('Number of determinants: {}'.format(vt.get_number_of_determinants(mol)))\n",
" xyz = ob.get_xyz(mol)\n",
" info = 'Molecular formula: {}\\n'.format(ob.get_formula(mol))\n",
" info += 'Multiplicity: {}\\n'.format(ob.get_multiplicity(mol))\n",
" info += 'Number of electrons: {}\\n'.format(ob.get_nelectron(mol))\n",
" info += 'Number of determinants: {}\\n'.format(vt.get_number_of_determinants(mol))\n",
" info += 'xyz:\\n {}\\n'.format(xyz)\n",
" try:\n",
" import py3Dmol\n",
" xyzview = py3Dmol.view(width=100,height=100)\n",
" xyzview.addModel(xyz,'xyz')\n",
" xyzview.setStyle({'stick':{'radius':0.5}})\n",
" xyzview.setBackgroundColor('0xeeeeee')\n",
" xyzview.animate({'loop': 'backAndForth'})\n",
" xyzview.zoomTo()\n",
" molview = xyzview.show()\n",
" except Exception as e:\n",
" pass\n",
" w1 = Textarea(value=info,description='info',layout={'height': '100px','width':'400px'}) \n",
" display(w1)\n",
" orb = vt.get_guess_orbital(mol,basis,fullbasis=fullbasis, allatoms=allatoms)\n",
" inp = vt.get_valence_input(mol,basis,guess=orb,fullbasis=fullbasis,allatoms=allatoms)\n",
" w = Textarea(value=inp,layout={'height': '500px','width':'50%'},description='input')\n",
" display(w)\n",
" if optimization == 'very tight':\n",
" opt = '16 16 16 10 10'\n",
" elif optimization == 'tight':\n",
" opt = '12 12 12 5 5'\n",
" elif optimization == 'coarse':\n",
" opt = '5 5 5 0 0'\n",
" elif optimization == 'very coarse':\n",
" opt = '1 1 1 0 0'\n",
" else:\n",
" opt = '10 10 10 0 0'\n",
" opt = opt + ' ' + str(niter)\n",
" inp = vt.get_valence_input(mol,basis,guess=orb,fullbasis=fullbasis,allatoms=allatoms,opt=opt)\n",
" w2 = Textarea(value=inp,layout={'height': '500px','width':'600px'},description='input')\n",
" display(w2)\n",
" return "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "valence-env",
"language": "python",
"name": "python2"
"name": "valence-env"
},
"language_info": {
"codemirror_mode": {
Expand Down
2 changes: 1 addition & 1 deletion vtools/iotools.py
Expand Up @@ -488,7 +488,7 @@ def run(inp, exe):
"""
"""
from subprocess import Popen, PIPE
process = Popen(exe, stdin= PIPE, stdout=PIPE, stderr=PIPE, encoding='utf8')
process = Popen(exe, stdin= PIPE, stdout=PIPE, stderr=PIPE)
out, err = process.communicate(input=inp)
if err:
logging.error('ERROR in iotools.run: {}'.format(err))
Expand Down
38 changes: 26 additions & 12 deletions vtools/vtools.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python

from __future__ import absolute_import, division, print_function, unicode_literals
from . import obtools as ob
from . import iotools as io
#from __future__ import absolute_import, division, print_function, unicode_literals
import logging
import json
import obtools as ob
import iotools as io
try:
#from ebsel.ebsel import EMSL_local #not sure why this line doesn't work with python2.7
from ebsel.EMSL_local import EMSL_local
Expand Down Expand Up @@ -33,15 +33,22 @@ def get_number_of_determinants(x):
Return the number of determinants for the VALENCE calculation.
Calculated by the formula:
Number_of_det = 3 * n**4 / 2 - n**3 + 15 * n**2 / 2 - 2 * n
where n is the number of orbitals.
Parameters
-----------
x: int or any object that can return a mol object with obtools get_mol()
x: int (number of electrons) or any object that can return a mol object with obtools get_mol()
"""
import math
try:
nelec = x + 2 - 2
except TypeError:
nelec = ob.get_nelectron(x)
return int(3*nelec**4/2-nelec**3+15*nelec**2/2-2*nelec)
norb = math.ceil(ob.get_nelectron(x) / 2)
except:
try:
norb = math.ceil(x / 2)
except TypeError:
logging.error("The input for get_number_of_determinants should be either an integer "
"for the number of electrons or an object that can return a mol object with ob.get_mol")
return 0
return int(3*norb**4/2-norb**3+15*norb**2/2-2*norb)


def get_unique_atomic_numbers(x):
Expand All @@ -68,7 +75,9 @@ def get_unique_atomic_numbers(x):

def get_nlonepair(mol,unique=False):
"""

Return the number of lone-pair orbitals. Currently
considers only O and N atoms as bearers of lone-pair
orbitals.
"""
symbols = ob.get_symbol_list(mol)
if unique:
Expand Down Expand Up @@ -1533,7 +1542,7 @@ def main():
mkinputfile = io.get_unique_filename(prefix + '_mk.inp')
print('Modelkit input file: {}'.format(mkinputfile))
io.write_file(mkinput,mkinputfile)
if io.check_file(modelkit):
if io.check_exe(modelkit):
guess = io.run(mkinput, modelkit)
else:
print('Cannot find {}. Specify the path to modelkit executable with --modelkit <pathtomodelkit>'.format(modelkit))
Expand Down Expand Up @@ -1566,6 +1575,11 @@ def main():
print('VALENCE output: \n {}'.format(valenceoutput))
return 0


if __name__ == "__main__":
if __name__ == '__main__':
if __package__ is None:
import sys
from os import path
sys.path.append( path.dirname( path.dirname( path.abspath(__file__) ) ) )
import obtools as ob
import iotools as io
main()