├── chemtools ├── pescan │ ├── __init__.py │ └── controller.py ├── __init__.py ├── calculators │ ├── __init__.py │ ├── dmft.py │ ├── psi4.py │ ├── molpro.py │ ├── calculator.py │ ├── dalton.py │ └── gamessorbitals.py ├── cli.py ├── parsetools.py ├── submitmolpro.py ├── molecule.py └── cbs.py ├── doc ├── requirements.txt ├── source │ ├── install.rst │ ├── tutorial.rst │ ├── api.rst │ ├── index.rst │ ├── notebooks │ │ ├── Molpro_tutorial.ipynb │ │ └── GamessUS_tutorial.ipynb │ └── conf.py ├── Makefile └── make.bat ├── setup.cfg ├── tests ├── test_gamessus │ ├── data │ │ ├── he │ │ │ ├── he_mini_hf.F08 │ │ │ ├── he_mini_hf.F10 │ │ │ ├── he_mini_hf.F05 │ │ │ ├── he_mini_hf.inp │ │ │ └── he_mini_hf.dat │ │ ├── ne │ │ │ ├── ne_dz_guga.F08 │ │ │ ├── ne_dz_guga.F09 │ │ │ ├── ne_dz_guga.F10 │ │ │ ├── ne_dz_guga.F15 │ │ │ ├── ne_dz_guga_rdm2.npy │ │ │ ├── ne_dz_guga_aoints.npy │ │ │ ├── ne_dz_guga_moints.npy │ │ │ ├── ne_dz_guga.inp │ │ │ └── ne_dz_guga.dat │ │ └── heh2 │ │ │ ├── he-h2_avdz_ormas.F08 │ │ │ ├── he-h2_avdz_ormas.F09 │ │ │ ├── he-h2_avdz_ormas.F10 │ │ │ ├── he-h2_avdz_ormas.F12 │ │ │ ├── he-h2_avdz_ormas.F05 │ │ │ └── he-h2_avdz_ormas.inp │ ├── test_SequentialFile.py │ └── test_GamessInput.py ├── test_basisopt │ ├── test_basisopt_initialization.py │ ├── test_molpro_exps_powell.py │ ├── test_dalton_eventemp.py │ ├── test_molpro_sp_tight_Be.py │ ├── test_gamessus_be2_midbond_cg.py │ ├── test_dalton_aug_BeH-.py │ ├── test_psi4_exps_aug_BeH-.py │ └── test_shell_optimization.py ├── test_molecule │ └── test_Atom.py ├── test_basisset │ ├── test_basisset_json_io.py │ └── test_basisset_parsers.py └── test_cbs │ └── test_cbs.py ├── examples ├── ipython_notebooks │ └── data │ │ ├── h2_eq_pvtz_fci.F08 │ │ ├── h2_eq_pvtz_fci.F09 │ │ ├── h2_eq_pvtz_fci.F10 │ │ ├── h2_eq_pvtz_fci.F11 │ │ ├── h2_eq_pvtz_fci.F12 │ │ ├── h2_eq_pvtz_fci.F15 │ │ ├── h2_eq_pvtz_fci.F16 │ │ ├── h2_eq_pvtz_fci.F14.7z │ │ ├── h2_eq_pvtz_fci.F05 │ │ └── h2_eq_pvtz_fci.inp ├── be_molpro_hf_10s5p_eventemp │ ├── molpro.inp │ ├── ccpvdz_molpro.bas │ └── be_molpro_hf_10s5p_eventemp.py ├── he_14s_legendre │ └── he_14s_legendre_molpro.py └── BasisSetClass │ └── h_av6z.bas ├── MANIFEST.in ├── .readthedocs.yaml ├── conda-recipe ├── build.sh ├── bld.bat └── meta.yaml ├── .bumpversion.cfg ├── tox.ini ├── pyproject.toml ├── .travis.yml ├── LICENSE.rst ├── setup.py ├── .gitignore └── README.rst /chemtools/pescan/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | #import model 5 | #import controller 6 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | numba 3 | mendeleev 4 | scipy 5 | sqlalchemy 6 | guzzle_sphinx_theme 7 | nbsphinx 8 | ipython 9 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [build_sphinx] 2 | source-dir = doc/source 3 | build-dir = doc/build 4 | all_files = 1 5 | [aliases] 6 | test=pytest 7 | -------------------------------------------------------------------------------- /tests/test_gamessus/data/he/he_mini_hf.F08: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/he/he_mini_hf.F08 -------------------------------------------------------------------------------- /tests/test_gamessus/data/he/he_mini_hf.F10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/he/he_mini_hf.F10 -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga.F08: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/ne/ne_dz_guga.F08 -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga.F09: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/ne/ne_dz_guga.F09 -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga.F10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/ne/ne_dz_guga.F10 -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga.F15: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/ne/ne_dz_guga.F15 -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga_rdm2.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/ne/ne_dz_guga_rdm2.npy -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga_aoints.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/ne/ne_dz_guga_aoints.npy -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga_moints.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/ne/ne_dz_guga_moints.npy -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F08: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/examples/ipython_notebooks/data/h2_eq_pvtz_fci.F08 -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F09: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/examples/ipython_notebooks/data/h2_eq_pvtz_fci.F09 -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/examples/ipython_notebooks/data/h2_eq_pvtz_fci.F10 -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/examples/ipython_notebooks/data/h2_eq_pvtz_fci.F11 -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/examples/ipython_notebooks/data/h2_eq_pvtz_fci.F12 -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F15: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/examples/ipython_notebooks/data/h2_eq_pvtz_fci.F15 -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/examples/ipython_notebooks/data/h2_eq_pvtz_fci.F16 -------------------------------------------------------------------------------- /tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F08: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F08 -------------------------------------------------------------------------------- /tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F09: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F09 -------------------------------------------------------------------------------- /tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F10 -------------------------------------------------------------------------------- /tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F12 -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F14.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmmentel/chemtools/HEAD/examples/ipython_notebooks/data/h2_eq_pvtz_fci.F14.7z -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include doc/Makefile 2 | include doc/source/*.rst 3 | include doc/source/conf.py 4 | include doc/source/notebooks/*.ipynb 5 | include README.rst 6 | include LICENSE.rst 7 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: "ubuntu-20.04" 5 | tools: 6 | python: "3.8" 7 | 8 | python: 9 | install: 10 | - requirements: doc/requirements.txt -------------------------------------------------------------------------------- /chemtools/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | chemtools package doscstring 5 | ''' 6 | 7 | __version__ = "0.9.2" 8 | 9 | import chemtools.basisset 10 | import chemtools.basisopt 11 | 12 | -------------------------------------------------------------------------------- /examples/be_molpro_hf_10s5p_eventemp/molpro.inp: -------------------------------------------------------------------------------- 1 | ***,h2o test 2 | memory,100,m !allocate 500 MW dynamic memory 3 | 4 | geometry 5 | 6 | basis 7 | 8 | core 9 | 10 | {rhf; wf,4,1,0} 11 | -------------------------------------------------------------------------------- /chemtools/calculators/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | chemtools.calculators package doscstring 5 | ''' 6 | 7 | from .dalton import Dalton 8 | from .molpro import Molpro 9 | 10 | __version__ = "0.9.2" 11 | 12 | -------------------------------------------------------------------------------- /conda-recipe/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | $PYTHON setup.py install 4 | 5 | # Add more build steps here, if they are necessary. 6 | 7 | # See 8 | # http://docs.continuum.io/conda/build.html 9 | # for a list of environment variables that are set during the build process. 10 | -------------------------------------------------------------------------------- /conda-recipe/bld.bat: -------------------------------------------------------------------------------- 1 | "%PYTHON%" setup.py install 2 | if errorlevel 1 exit 1 3 | 4 | :: Add more build steps here, if they are necessary. 5 | 6 | :: See 7 | :: http://docs.continuum.io/conda/build.html 8 | :: for a list of environment variables that are set during the build process. 9 | -------------------------------------------------------------------------------- /doc/source/install.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Installation 3 | ============ 4 | 5 | Using pip 6 | ========= 7 | 8 | If you don't have ``pip`` you should probably me your life easier and get it, 9 | the installation instructions can be found `here `_. Once you have it type 10 | 11 | $ pip install chemtools 12 | -------------------------------------------------------------------------------- /tests/test_gamessus/data/he/he_mini_hf.F05: -------------------------------------------------------------------------------- 1 | $CONTRL 2 | scftyp=rhf 3 | runtyp=energy 4 | maxit=30 5 | mult=1 6 | ispher=1 7 | units=bohr 8 | exetyp=debug 9 | nprint=4 10 | $END 11 | $SYSTEM 12 | timlim=525600 13 | mwords=200 14 | $END 15 | $BASIS gbasis=mini $END 16 | $DATA 17 | He dimer VDW equilibrium 18 | dnh 2 19 | 20 | He 2.0 0.00000 0.00000 0.00000 21 | $END 22 | -------------------------------------------------------------------------------- /tests/test_gamessus/data/he/he_mini_hf.inp: -------------------------------------------------------------------------------- 1 | $CONTRL 2 | scftyp=rhf 3 | runtyp=energy 4 | maxit=30 5 | mult=1 6 | ispher=1 7 | units=bohr 8 | exetyp=debug 9 | nprint=4 10 | $END 11 | $SYSTEM 12 | timlim=525600 13 | mwords=200 14 | $END 15 | $BASIS gbasis=mini $END 16 | $DATA 17 | He dimer VDW equilibrium 18 | dnh 2 19 | 20 | He 2.0 0.00000 0.00000 0.00000 21 | $END 22 | -------------------------------------------------------------------------------- /.bumpversion.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 0.9.2 3 | commit = True 4 | tag = True 5 | 6 | [bumpversion:file:setup.py] 7 | 8 | [bumpversion:file:README.rst] 9 | 10 | [bumpversion:file:chemtools/__init__.py] 11 | 12 | [bumpversion:file:chemtools/calculators/__init__.py] 13 | 14 | [bumpversion:file:doc/source/conf.py] 15 | 16 | [bumpversion:file:doc/source/index.rst] 17 | 18 | [bumpversion:file:conda-recipe/meta.yaml] 19 | 20 | [bumpversion:file:pyproject.toml] 21 | 22 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # Tox (http://tox.testrun.org/) is a tool for running tests 2 | # in multiple virtualenvs. This configuration file will run the 3 | # test suite on all supported python versions. To use it, "pip install tox" 4 | # and then run "tox" from this directory. 5 | 6 | [tox] 7 | envlist = py34 8 | 9 | [testenv] 10 | changedir=tests 11 | whitelist_externals=/usr/local/bin/py.test 12 | deps = pytest 13 | sitepackages=True 14 | commands = 15 | py.test \ 16 | --basetemp={envtmpdir} {posargs} 17 | -------------------------------------------------------------------------------- /tests/test_basisopt/test_basisopt_initialization.py: -------------------------------------------------------------------------------- 1 | 2 | import pytest 3 | from chemtools.basisopt import BSOptimizer 4 | 5 | 6 | def test_fsopt_validation(): 7 | 8 | with pytest.raises(ValueError): 9 | 10 | fsopt = {'Be': [('z', 'exp', 1, (0.27173,))]} 11 | BSOptimizer(fsopt=fsopt) 12 | 13 | with pytest.raises(ValueError): 14 | 15 | fsopt = {'Be': [('s', 'other', 1, (0.27173,))]} 16 | BSOptimizer(fsopt=fsopt) 17 | 18 | with pytest.raises(ValueError): 19 | 20 | fsopt = {'Be': [('s', None, 1, (0.27173,))]} 21 | BSOptimizer(fsopt=fsopt) 22 | -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga.inp: -------------------------------------------------------------------------------- 1 | $CONTRL 2 | SCFTYP=RHF 3 | RUNTYP=ENERGY 4 | CITYP=GUGA 5 | MAXIT=30 6 | MULT=1 7 | ISPHER=1 8 | ICHARG=0 9 | ! exetyp=debug 10 | $END 11 | $SYSTEM TIMLIM=14400 MWORDS=100 MEMDDI=0 $END 12 | $SCF 13 | DIRSCF=.F. 14 | $END 15 | $CIINP 16 | nrnfg(6)=1 17 | $END 18 | $CIDRT 19 | iexcit=3 20 | nfzc=0 21 | ndoc=5 22 | nval=9 23 | group=d2h 24 | ! STSYM=AG 25 | $END 26 | ! $GUGDIA 27 | ! CVGTOL=1.0E-10 28 | ! $END 29 | $BASIS GBASIS=CCD $END 30 | $DATA 31 | Title 32 | dNh 2 33 | 34 | NE 10.0 0.00000000 0.00000000 0.0000000 35 | $END 36 | -------------------------------------------------------------------------------- /examples/be_molpro_hf_10s5p_eventemp/ccpvdz_molpro.bas: -------------------------------------------------------------------------------- 1 | !BAZA Petersona 2 | s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02; 3 | c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03; 4 | c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01; 5 | c,9.9,1.000000E+00; 6 | 7 | p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02; 8 | c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01; 9 | c,4.4,1.000000E+00; 10 | ! 11 | !d,Be,2.354000E-01; 12 | !c,1.1,1.000000E+00; 13 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "chemtools" 3 | version = "0.9.2" 4 | description = "Python tools for quantum chemical calculations" 5 | authors = ["Lukasz Mentel "] 6 | license = "MIT" 7 | 8 | [tool.poetry.dependencies] 9 | python = ">=3.9,<3.13" 10 | sqlalchemy = "^1.3.13" 11 | scipy = "^1.10.0" 12 | numpy = "^1.18.1" 13 | mendeleev = "^0.5.2" 14 | numba = "^0.48.0" 15 | pandas = "^1.0.1" 16 | 17 | [tool.poetry.dev-dependencies] 18 | sphinx = "^2.4.4" 19 | pytest = "^5.3.5" 20 | guzzle_sphinx_theme = "^0.7.11" 21 | nbsphinx = "^0.5.1" 22 | ipython = "^8.10.0" 23 | bumpversion = "^0.5.3" 24 | jupyterlab = "^3.2.8" 25 | 26 | [build-system] 27 | requires = ["poetry>=0.12"] 28 | build-backend = "poetry.masonry.api" 29 | -------------------------------------------------------------------------------- /tests/test_gamessus/data/he/he_mini_hf.dat: -------------------------------------------------------------------------------- 1 | $DATA 2 | He dimer VDW equilibrium 3 | DNH 2 4 | 5 | HE 2.0 0.0000000000 0.0000000000 0.0000000000 6 | MINI 0 7 | 8 | $END 9 | --- CLOSED SHELL ORBITALS --- GENERATED AT Wed Jul 30 02:19:03 2014 10 | He dimer VDW equilibrium 11 | E(RHF)= -2.8356798736, E(NUC)= 0.0000000000, 2 ITERS 12 | $VEC 13 | 1 1 1.00000000E+00 14 | $END 15 | POPULATION ANALYSIS 16 | HE 2.00000 -0.00000 2.00000 0.00000 17 | MOMENTS AT POINT 1 X,Y,Z= 0.000000 0.000000 0.000000 18 | DIPOLE 0.000000 0.000000 0.000000 19 | -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.F05: -------------------------------------------------------------------------------- 1 | $CONTRL scftyp=rhf runtyp=energy maxit=30 mult=1 ispher=1 2 | itol=30 icut=30 units=bohr cityp=guga qmttol=1.0e-8 $END 3 | $SYSTEM timlim=525600 mwords=100 $END 4 | $SCF dirscf=.false. $END 5 | $CIDRT iexcit=2 nfzc=0 ndoc=1 nval=27 group=d2h stsym=ag 6 | mxnint=14307305 nprt=2 $END 7 | $GUGDIA prttol=1.0e-6 cvgtol=1.0e-10 $END 8 | $DATA 9 | H2 cc-pVTZ 10 | dnh 2 11 | 12 | H 1.00 0.000000 0.000000 0.700000 13 | S 3 14 | 1 33.8700000 0.0060680 15 | 2 5.0950000 0.0453080 16 | 3 1.1590000 0.2028220 17 | S 1 18 | 1 0.3258000 1.0000000 19 | S 1 20 | 1 0.1027000 1.0000000 21 | P 1 22 | 1 1.4070000 1.0000000 23 | P 1 24 | 1 0.3880000 1.0000000 25 | D 1 26 | 1 1.0570000 1.0000000 27 | 28 | $END 29 | -------------------------------------------------------------------------------- /examples/ipython_notebooks/data/h2_eq_pvtz_fci.inp: -------------------------------------------------------------------------------- 1 | $CONTRL scftyp=rhf runtyp=energy maxit=30 mult=1 ispher=1 2 | itol=30 icut=30 units=bohr cityp=guga qmttol=1.0e-8 $END 3 | $SYSTEM timlim=525600 mwords=100 $END 4 | $SCF dirscf=.false. $END 5 | $CIDRT iexcit=2 nfzc=0 ndoc=1 nval=27 group=d2h stsym=ag 6 | mxnint=14307305 nprt=2 $END 7 | $GUGDIA prttol=1.0e-6 cvgtol=1.0e-10 $END 8 | $DATA 9 | H2 cc-pVTZ 10 | dnh 2 11 | 12 | H 1.00 0.000000 0.000000 0.700000 13 | S 3 14 | 1 33.8700000 0.0060680 15 | 2 5.0950000 0.0453080 16 | 3 1.1590000 0.2028220 17 | S 1 18 | 1 0.3258000 1.0000000 19 | S 1 20 | 1 0.1027000 1.0000000 21 | P 1 22 | 1 1.4070000 1.0000000 23 | P 1 24 | 1 0.3880000 1.0000000 25 | D 1 26 | 1 1.0570000 1.0000000 27 | 28 | $END 29 | -------------------------------------------------------------------------------- /doc/source/tutorial.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | Tutorials 3 | ========= 4 | 5 | .. toctree:: 6 | 7 | notebooks/BasisSet_tutorial.ipynb 8 | notebooks/BasisOpt_tutorial.ipynb 9 | notebooks/Molpro_tutorial.ipynb 10 | notebooks/GamessUS_tutorial.ipynb 11 | 12 | 13 | Jupyter Notebooks 14 | ================= 15 | 16 | The tutorials are also avaiable as `Jupyter `_ 17 | notebooks: 18 | 19 | - `BasisSet `_ 20 | - `Basis set optimization `_ 21 | - `Gamess(US) wrapper `_ 22 | - `Molpro wrapper `_ 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/test_molecule/test_Atom.py: -------------------------------------------------------------------------------- 1 | 2 | import unittest 3 | from chemtools import molecule 4 | 5 | 6 | class TestAtomAN(unittest.TestCase): 7 | 8 | def setUp(self): 9 | self.h = molecule.Atom(1) 10 | 11 | def tearDown(self): 12 | del self.h 13 | 14 | def test_Atom_default(self): 15 | 16 | self.assertEqual('H', self.h.symbol) 17 | self.assertEqual('Hydrogen', self.h.name) 18 | self.assertEqual(1, self.h.atomic_number) 19 | self.assertEqual(1.008, self.h.mass) 20 | 21 | 22 | class TestAtomSymbol(unittest.TestCase): 23 | 24 | def setUp(self): 25 | self.o = molecule.Atom('O') 26 | 27 | def tearDown(self): 28 | del self.o 29 | 30 | def test_Atom_default(self): 31 | 32 | self.assertEqual('O', self.o.symbol) 33 | self.assertEqual('Oxygen', self.o.name) 34 | self.assertEqual(8, self.o.atomic_number) 35 | self.assertEqual(15.999, self.o.mass) 36 | 37 | 38 | if __name__ == "__main__": 39 | unittest.main() 40 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - '3.6' 4 | - '3.7' 5 | - '3.8' 6 | install: 7 | - pip install . 8 | - pip install pytest 9 | script: 10 | - pytest tests 11 | deploy: 12 | provider: pypi 13 | user: __token__ 14 | password: 15 | secure: mBIibiwVXaFsfjN89+7+6AIOPt57JFgmIAg1OpnW6Ug0qNJc9v4Td41t1CA5K/GUtiqbch/FFnZR/UXMDpxte7J+tF/KpV3FeQ+tHfJQsjTYZ05eM5kErBxupyNrcLOPy3jD0gWHCtyoh1K5y8luXJ4aKsBQJlVluJbZ3WvbIrjsuyha5X7xUyl4cm1GJBIjcuUo8qNRBEQ3EV91UopmDCawg93QDjiENSAlzTfkXo/CcWQZ1MRudaGr+7XsuylcML/FQmR7YL2675wW0bdxwGHBZhF954FbtFJiAcs43EQZadMVOHAdFnTT9IAfdsJ+wmYdiaer8RTWH2jDfZnRxqL1mmmiJPU1LxYZSCuMOQySB2hjjRKf9m1ErnK0l5i93a9NYI7WG6r6S+I7R53YCmR6GG++N6st/8SfSEwhuVgFrx2iXId13zec2pjMvAvahPwQUKhyPSdZdxqUWc28UxyzRKdY3LILAltSJiP50WYqZSWPj68HUlXs1+yuPCwYb5W8o/JKlGkfvo5LL67zTluy2LN8wacCGopkF1P8oY4gQUbVwVRQfZIceQ8pb+C7AI6hIb6lrMhZOC20xlVrXCm1jmlMDVKu6lhBNQ1osVIqa5NBW4dBiTgX62S3HJzHfWE7GRbZAhRrZ+PV89FAsvRmnSpJ9KNKBNgH5OgkJVE= 16 | on: 17 | tags: true 18 | skip_existing: true 19 | distributions: "sdist bdist_wheel" 20 | -------------------------------------------------------------------------------- /LICENSE.rst: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Lukasz Mentel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /conda-recipe/meta.yaml: -------------------------------------------------------------------------------- 1 | package: 2 | name: chemtools 3 | version: "0.9.2" 4 | 5 | source: 6 | hg_url: https://bitbucket.org/lukaszmentel/chemtools 7 | hg_tag: v0.9.2 8 | 9 | build: 10 | # noarch_python: True 11 | # preserve_egg_dir: True 12 | entry_points: 13 | 14 | - bsprint = chemtools.basisset:bsprint 15 | - bsconvert = chemtools.basisset:bsconvert 16 | - writeorbinp = chemtools.calculators.gamessus:writeorbinp 17 | 18 | # If this is a new build for the same version, increment the build 19 | # number. If you do not include this key, it defaults to 0. 20 | number: 0 21 | 22 | channels: 23 | - lmmentel 24 | 25 | requirements: 26 | build: 27 | - python 28 | - setuptools 29 | - mendeleev 30 | - numba 31 | - numpy 32 | - scipy 33 | - pandas 34 | run: 35 | - python 36 | - numpy 37 | - scipy 38 | - pandas 39 | - numba 40 | - sqlalchemy 41 | - mendeleev 42 | 43 | test: 44 | # Python imports 45 | imports: 46 | - chemtools 47 | 48 | commands: 49 | - bsprint --help 50 | - bsconvert --help 51 | - writeorbinp --help 52 | 53 | about: 54 | home: http://chemtools.readthedocs.org/en/latest/ 55 | summary: A library of tools for manipulating one-electron basis sets including format conversions, 56 | optimization of exponents, visualization of completeness profiles, CBS extrapolations 57 | and more. 58 | license: MIT 59 | license_file: LICENSE.rst 60 | -------------------------------------------------------------------------------- /tests/test_basisopt/test_molpro_exps_powell.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | import pytest 4 | from chemtools.basisopt import BSOptimizer 5 | from chemtools.molecule import Molecule 6 | from chemtools.calculators.molpro import Molpro 7 | 8 | 9 | @pytest.mark.skipif(os.getenv('MOLPRO_EXE') is None, 10 | reason=" undefined") 11 | def test_molpro_exps_opt(tmpdir): 12 | 13 | tmpdir.chdir() 14 | 15 | template = '''***,he 16 | memory,100,m 17 | GTHRESH,THROVL=1.0e-9 18 | 19 | %geometry 20 | 21 | %basis 22 | 23 | %core 24 | 25 | {rhf; wf,2,1,0} 26 | 27 | ''' 28 | 29 | he = Molecule(name="He", atoms=[('He',)], charge=0, multiplicity=1) 30 | 31 | optimization = {"method": "Powell", 32 | "tol": 1.0e-5, 33 | "jacob": False, 34 | "options": {"maxiter": 100, "disp": True}} 35 | 36 | mp = Molpro(exevar="MOLPRO_EXE", runopts=["-s", "-n", "1", "-d", "."]) 37 | 38 | exps = (1.00473157e+03, 3.51102141e+02, 1.35742439e+02, 39 | 5.69386800e+01, 2.51416924e+01, 1.15836670e+01, 40 | 5.23629402e+00, 2.38685192e+00, 7.60836609e-01) 41 | 42 | sfuncts = {'He': [('s', 'exp', 9, exps)]} 43 | 44 | bso = BSOptimizer(objective='hf total energy', template=template, code=mp, 45 | mol=he, fsopt=sfuncts, staticbs=None, 46 | core=[0, 0, 0, 0, 0, 0, 0, 0], fname='molpro_powell.inp', 47 | verbose=True, uselogs=True, optalg=optimization) 48 | 49 | bso.run() 50 | 51 | energy = -2.8614232306 52 | assert abs(bso.result.fun - energy) < 1.0e-8, 'wrong objective' 53 | -------------------------------------------------------------------------------- /tests/test_basisopt/test_dalton_eventemp.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | from chemtools.calculators.dalton import Dalton 4 | from chemtools.molecule import Molecule 5 | from chemtools.basisopt import BSOptimizer 6 | import pytest 7 | 8 | 9 | @pytest.mark.skipif(os.getenv('DALTON_EXE') is None, 10 | reason=" undefined") 11 | def test_optimize(tmpdir): 12 | 13 | tmpdir.chdir() 14 | 15 | moltemplate = '''INTGRL 16 | basis set optimization 17 | test dalton calculator 18 | Atomtypes=1 Integrals=1.0D-20 19 | %basis 20 | ''' 21 | 22 | hftemplate = '''**DALTON INPUT 23 | .RUN WAVE FUNCTIONS 24 | **WAVE FUNCTION 25 | .HF 26 | **END OF DALTON INPUT 27 | ''' 28 | 29 | daltemplate = '''**DALTON INPUT 30 | .RUN WAVE FUNCTIONS 31 | **WAVE FUNCTIONS 32 | .HF 33 | .GASCI 34 | *LUCITA 35 | .INIWFC 36 | HF_SCF 37 | .CITYPE 38 | GASCI 39 | .SYMMET 40 | 1 41 | .MULTIP 42 | 1 43 | .INACTIVE 44 | %core 45 | .GAS SHELLS 46 | 1 47 | 0 2 / 39 30 30 20 30 20 20 14 48 | .NROOTS 49 | 1 50 | **END OF DALTON INPUT 51 | ''' 52 | 53 | dalton = Dalton(exevar='DALTON_EXE', 54 | runopts=['-nobackup', '-noarch', '-d']) 55 | 56 | fname = {'dal': 'hf.dal', 'mol': 'He_5s.mol'} 57 | template = {'mol': moltemplate, 'dal': hftemplate} 58 | fsopt = {'He': [('s', 'et', 5, (0.5, 2.0))]} 59 | he = Molecule(name='He', atoms=[('He', )]) 60 | bso = BSOptimizer(objective='hf total energy', template=template, 61 | verbose=False, code=dalton, mol=he, fsopt=fsopt, 62 | fname=fname) 63 | 64 | bso.run() 65 | energy = -2.8586246608170001 66 | assert abs(bso.result.fun - energy) < 1.0e-8, 'wrong objective' 67 | -------------------------------------------------------------------------------- /tests/test_gamessus/data/heh2/he-h2_avdz_ormas.F05: -------------------------------------------------------------------------------- 1 | $CONTRL 2 | scftyp=rhf 3 | cityp=ormas 4 | runtyp=energy 5 | maxit=30 6 | mult=1 7 | icut=30 8 | itol=30 9 | ispher=1 10 | units=bohr 11 | ! exetyp=check 12 | $END 13 | $SYSTEM timlim=525600 mwords=100 $END 14 | $SCF conv=1.0d-8 $END 15 | $TRANS cuttrf=1.0d-10 $END 16 | $CIDET 17 | ncore=0 18 | nact=27 19 | nels=4 20 | sz=0 21 | analys=.true. 22 | group=c2v 23 | stsym=a1 24 | ! nstate=1 25 | ! itermx=100 26 | ! cvgtol=1.0d-6 27 | ! nflgdm=1 28 | $END 29 | $ORMAS 30 | nspace=2 31 | mstart(1)=1,3 32 | mine(1)=0,0 33 | maxe(1)=4,4 34 | qcorr=.false. 35 | $END 36 | ! R_e(H-H) = 1.448 736 a_0 37 | $DATA 38 | He-H2 FCI 39 | cnv 2 40 | 41 | He 2.0 0.00000 0.000000 -3.000000 42 | S 3 43 | 1 38.3600000 0.0238090 44 | 2 5.7700000 0.1548910 45 | 3 1.2400000 0.4699870 46 | S 1 47 | 1 0.2976000 1.0000000 48 | S 1 49 | 1 0.0725500 1.0000000 50 | P 1 51 | 1 1.2750000 1.0000000 52 | P 1 53 | 1 0.2473000 1.0000000 54 | 55 | H 1.0 0.00000 0.724368 3.000000 56 | S 3 57 | 1 13.0100000 0.0196850 58 | 2 1.9620000 0.1379770 59 | 3 0.4446000 0.4781480 60 | S 1 61 | 1 0.1220000 1.0000000 62 | S 1 63 | 1 0.0297400 1.0000000 64 | P 1 65 | 1 0.7270000 1.0000000 66 | P 1 67 | 1 0.1410000 1.0000000 68 | 69 | $END 70 | -------------------------------------------------------------------------------- /tests/test_gamessus/data/heh2/he-h2_avdz_ormas.inp: -------------------------------------------------------------------------------- 1 | $CONTRL 2 | scftyp=rhf 3 | cityp=ormas 4 | runtyp=energy 5 | maxit=30 6 | mult=1 7 | icut=30 8 | itol=30 9 | ispher=1 10 | units=bohr 11 | ! exetyp=check 12 | $END 13 | $SYSTEM timlim=525600 mwords=100 $END 14 | $SCF conv=1.0d-8 $END 15 | $TRANS cuttrf=1.0d-10 $END 16 | $CIDET 17 | ncore=0 18 | nact=27 19 | nels=4 20 | sz=0 21 | analys=.true. 22 | group=c2v 23 | stsym=a1 24 | ! nstate=1 25 | ! itermx=100 26 | ! cvgtol=1.0d-6 27 | ! nflgdm=1 28 | $END 29 | $ORMAS 30 | nspace=2 31 | mstart(1)=1,3 32 | mine(1)=0,0 33 | maxe(1)=4,4 34 | qcorr=.false. 35 | $END 36 | ! R_e(H-H) = 1.448 736 a_0 37 | $DATA 38 | He-H2 FCI 39 | cnv 2 40 | 41 | He 2.0 0.00000 0.000000 -3.000000 42 | S 3 43 | 1 38.3600000 0.0238090 44 | 2 5.7700000 0.1548910 45 | 3 1.2400000 0.4699870 46 | S 1 47 | 1 0.2976000 1.0000000 48 | S 1 49 | 1 0.0725500 1.0000000 50 | P 1 51 | 1 1.2750000 1.0000000 52 | P 1 53 | 1 0.2473000 1.0000000 54 | 55 | H 1.0 0.00000 0.724368 3.000000 56 | S 3 57 | 1 13.0100000 0.0196850 58 | 2 1.9620000 0.1379770 59 | 3 0.4446000 0.4781480 60 | S 1 61 | 1 0.1220000 1.0000000 62 | S 1 63 | 1 0.0297400 1.0000000 64 | P 1 65 | 1 0.7270000 1.0000000 66 | P 1 67 | 1 0.1410000 1.0000000 68 | 69 | $END 70 | -------------------------------------------------------------------------------- /examples/be_molpro_hf_10s5p_eventemp/be_molpro_hf_10s5p_eventemp.py: -------------------------------------------------------------------------------- 1 | 2 | from chemtools.basisopt import driver 3 | from chemtools.molecule import Atom, Molecule 4 | from chemtools.molpro import Molpro 5 | from chemtools.basisset import BasisSet 6 | 7 | be = Molecule(name="Be", atoms=[Atom(at=4)], charge=0, multiplicity=1) 8 | 9 | optimization = {"method" : "Nelder-Mead", 10 | "lambda" : 10.0, 11 | "tol" : 1.0e-4, 12 | "options" : {"maxiter" : 500, 13 | "disp" : True, 14 | } 15 | } 16 | 17 | job = {"method" : "hf", 18 | "objective" : "total energy", 19 | "core" : [0,0,0,0,0,0,0,0], 20 | "inpname" : "be_hf_10s5p.inp", 21 | "inpdata" : open("molpro.inp", 'r').read(), 22 | "verbose" : True, 23 | } 24 | 25 | mp = Molpro( 26 | name="MOLPRO", 27 | executable="/home/lmentel/Programs/MOLPRO/molprop_2012_1_Linux_x86_64_i8/bin/molpro", 28 | runopts=["-s", "-n", "1", "-d", "/home/lmentel/scratch"], 29 | ) 30 | 31 | # a single element tuple must be followed by comma since otherwise its not 32 | # treated as a tuple for example (1.0) should be (1.0,) 33 | 34 | event = {"typ" : "eventemp", 35 | "name" : "aug", 36 | "params" : [(0.6, 3.03), (1.0, 3.0)], 37 | "nfpshell" : [10,5], 38 | "element" : "Be" 39 | } 40 | 41 | def main(): 42 | 43 | 44 | res = driver(code=mp, job=job, mol=be, bsopt=event, opt=optimization) 45 | 46 | print res.success 47 | print res.x 48 | print res.fun 49 | #save the basis set 50 | opt_basis = vars(BasisSet.from_optdict(res.x, event)) 51 | with open('optimized_functions.bas', 'wb') as ff: 52 | ff.write(str(opt_basis)) 53 | 54 | if __name__ == "__main__": 55 | main() 56 | -------------------------------------------------------------------------------- /examples/he_14s_legendre/he_14s_legendre_molpro.py: -------------------------------------------------------------------------------- 1 | from chemtools.basisopt import Job 2 | from chemtools.molecule import Atom, Molecule 3 | from chemtools.molpro import Molpro 4 | from chemtools import molpro 5 | from chemtools.basisset import BasisSet, get_x0 6 | 7 | template = '''***,h2o test 8 | memory,100,m !allocate 500 MW dynamic memory 9 | GTHRESH,THROVL=1.0e-9 10 | 11 | %geometry 12 | 13 | %basis 14 | 15 | %core 16 | 17 | {rhf; wf,2,1,0} 18 | 19 | ''' 20 | 21 | he = Molecule(name="He", atoms=[('He',)], charge=0, multiplicity=1) 22 | 23 | nm = {"method" : "Nelder-Mead", 24 | "tol" : 1.0e-4, 25 | "lambda" : 15.0, 26 | "options" : {"maxiter" : 100, "disp" : True}, 27 | } 28 | 29 | molpro = Molpro( 30 | name="MOLPRO", 31 | executable="/home/lmentel/Programs/molprop_2012_1_Linux_x86_64_i8/bin/molpro", 32 | runopts=["-s", "-n", "1", "-d", "/home/lmentel/scratch"], 33 | ) 34 | 35 | legendre = {"typ" : "legendre", 36 | "name" : "orbital", 37 | "params" : [(3.55090649, 6.54677461, 1.02692142, 0.31719821)], 38 | "nfpshell" : [14,], 39 | "element" : "He", 40 | "type" : "hf", 41 | } 42 | 43 | lege_sp = {"typ" : "legendre", 44 | "name" : "cc-pV6Z tight sp", 45 | "params" : [(2.9623643, 1.39661345, 0.5), (3.04754371, 1.55118609, 0.2),], 46 | "nfpshell" : [5, 5,], 47 | "element" : "He", 48 | "type" : "tight", 49 | } 50 | 51 | job = Job(calcmethod='hf', objective='total energy', core=[0,0,0,0,0,0,0,0], 52 | template=template, code=molpro, optalg=nm, mol=he, bsopt=legendre) 53 | 54 | def main(): 55 | 56 | # Energy from numerical HF solution: 57 | # total energy: -2.861680026576101 58 | 59 | job.run() 60 | print(job.results) 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /tests/test_basisopt/test_molpro_sp_tight_Be.py: -------------------------------------------------------------------------------- 1 | 2 | from chemtools.basisopt import BSOptimizer 3 | from chemtools.molecule import Molecule 4 | from chemtools.calculators.molpro import Molpro 5 | from chemtools.basisset import BasisSet 6 | import pytest 7 | import os 8 | 9 | 10 | @pytest.mark.skipif(os.getenv('MOLPRO_EXE') is None, 11 | reason=" undefined") 12 | def test_optimize(tmpdir): 13 | 14 | tmpdir.chdir() 15 | 16 | be = Molecule(name="Be", atoms=[('Be',)], charge=0, multiplicity=1) 17 | 18 | template = '''***,be ccpvdz tight fs test 19 | memory,100,m 20 | 21 | %geometry 22 | 23 | %basis 24 | 25 | %core 26 | 27 | {rhf; wf,4,1,0} 28 | cisd 29 | ''' 30 | 31 | mp = Molpro(exevar="MOLPRO_EXE", runopts=["-s", "-n", "1", "-d", "."]) 32 | 33 | corefs = {'Be': [('s', 'exp', 1, (1.1,)), ('p', 'exp', 1, (4.2,))]} 34 | 35 | ccpvdz_str = '''basis={ 36 | !BAZA Petersona 37 | s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02; 38 | c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03; 39 | c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01; 40 | c,9.9,1.000000E+00; 41 | 42 | p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02; 43 | c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01; 44 | c,4.4,1.000000E+00; 45 | ! 46 | !d,Be,2.354000E-01; 47 | !c,1.1,1.000000E+00; 48 | } 49 | ''' 50 | ccpvdz = BasisSet.from_str(ccpvdz_str, fmt='molpro') 51 | 52 | bso = BSOptimizer(objective='cisd total energy', 53 | core=[[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]], 54 | template=template, verbose=True, code=mp, mol=be, 55 | fsopt=corefs, staticbs={'Be': ccpvdz}, uselogs=True, 56 | runcore=True, fname='be_tight.inp') 57 | 58 | bso.run() 59 | coreenergy = -0.031510764610001019 60 | assert abs(bso.result.fun - coreenergy) < 1.0e-8, 'wrong objective' 61 | -------------------------------------------------------------------------------- /tests/test_basisopt/test_gamessus_be2_midbond_cg.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | import pytest 4 | from chemtools.basisopt import BSOptimizer 5 | from chemtools.molecule import Molecule 6 | from chemtools.calculators.gamessus import GamessUS 7 | from chemtools.basisset import BasisSet 8 | 9 | 10 | @pytest.mark.skipif(os.getenv('GAMESS_EXE') is None, 11 | reason=" undefined") 12 | def test_optimize(tmpdir): 13 | 14 | tmpdir.chdir() 15 | 16 | gamesstemp = ''' $CONTRL 17 | scftyp=rhf 18 | cityp=guga 19 | runtyp=energy 20 | maxit=30 21 | mult=1 22 | ispher=1 23 | units=bohr 24 | exetyp=run 25 | $END 26 | $SYSTEM 27 | timlim=525600 28 | mwords=100 29 | $END 30 | $CIDRT 31 | iexcit=2 32 | nfzc=2 33 | ndoc=2 34 | nval=40 35 | group=d2h 36 | $END 37 | 38 | %basis 39 | ''' 40 | 41 | be2X = Molecule(name="Be2", atoms=[('Be', (0.0, 0.0, -1.5)), 42 | ('H', (0.0, 0.0, 0.0), True), 43 | ('Be', (0.0, 0.0, 1.5))], 44 | sym="dnh 2", charge=0, multiplicity=1, unique=[0, 1]) 45 | 46 | bsstr = '''basis={ 47 | s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02; 48 | c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03; 49 | c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01; 50 | c,9.9,1.000000E+00; 51 | 52 | p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02; 53 | c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01; 54 | c,4.4,1.000000E+00; 55 | 56 | d,Be,2.354000E-01; 57 | c,1.1,1.000000E+00; 58 | } 59 | ''' 60 | 61 | vdz = BasisSet.from_str(bsstr, fmt='molpro') 62 | 63 | optimization = {"method": "CG", 64 | "tol": 1.0e-4, 65 | "jacob": False, 66 | "options": {"maxiter": 100, "disp": True, 'eps': 1.0e-3}} 67 | 68 | gams = GamessUS(exevar="GAMESS_EXE", runopts=['1']) 69 | 70 | midbond = {'H': [('s', 'et', 4, (0.05, 2.0)), 71 | ('p', 'et', 4, (0.04, 2.0))]} 72 | 73 | bso = BSOptimizer(objective='cisd total energy', template=gamesstemp, 74 | code=gams, mol=be2X, fsopt=midbond, staticbs={'Be': vdz}, 75 | core=2, fname='midbond.inp', verbose=True, 76 | optalg=optimization) 77 | 78 | bso.run() 79 | energy = -29.1326831928 80 | assert abs(bso.result.fun - energy) < 1.0e-8, 'wrong objective' 81 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | 2 | ''' Chemtools setup script''' 3 | 4 | from setuptools import setup 5 | from setuptools.command.test import test as TestCommand 6 | import sys 7 | 8 | 9 | class Tox(TestCommand): 10 | 11 | # user_options = [('tox-args=', 'a', "Arguments to pass to tox")] 12 | 13 | def initialize_options(self): 14 | TestCommand.initialize_options(self) 15 | self.tox_args = None 16 | 17 | def finalize_options(self): 18 | TestCommand.finalize_options(self) 19 | self.test_args = [] 20 | self.test_suite = True 21 | 22 | def run_tests(self): 23 | # import here, cause outside the eggs aren't loaded 24 | import tox 25 | import shlex 26 | args = self.tox_args 27 | if args: 28 | args = shlex.split(self.tox_args) 29 | errno = tox.cmdline(args=args) 30 | sys.exit(errno) 31 | 32 | 33 | def readme(): 34 | '''Return the contents of the README.rst file.''' 35 | with open('README.rst', encoding='utf8') as freadme: 36 | return freadme.read() 37 | 38 | 39 | setup( 40 | author="Lukasz Mentel", 41 | author_email="lmmentel@gmail.com", 42 | description="Python tools for quantum chemical calculations", 43 | include_package_data=True, 44 | install_requires=[ 45 | 'sqlalchemy', 46 | 'scipy >= 0.11', 47 | 'numpy >= 1.7', 48 | 'mendeleev', 49 | 'numba', 50 | 'pandas'], 51 | entry_points={ 52 | 'console_scripts': [ 53 | 'writeorbinp = chemtools.calculators.gamessus:writeorbinp', 54 | 'bsconvert = chemtools.cli:bsconvert', 55 | 'bsprint = chemtools.cli:bsprint', 56 | ] 57 | }, 58 | license='MIT', 59 | long_description=readme(), 60 | long_description_content_type='text/x-rst', 61 | name='chemtools', 62 | packages=['chemtools', 'chemtools/pescan', 'chemtools/calculators'], 63 | scripts=[ 64 | 'chemtools/submitgamess.py', 65 | 'chemtools/submitmolpro.py'], 66 | url='https://github.com/lmmentel/chemtools/', 67 | version='0.9.2', 68 | classifiers=[ 69 | 'Development Status :: 5 - Production/Stable', 70 | 'Environment :: Console', 71 | 'Intended Audience :: Science/Research', 72 | 'License :: OSI Approved :: MIT License', 73 | 'Operating System :: OS Independent', 74 | 'Programming Language :: Python :: 3', 75 | 'Topic :: Scientific/Engineering :: Chemistry', 76 | 'Topic :: Scientific/Engineering :: Physics'], 77 | keywords=['basis set', 'optimization', 'quantum chemistry', 78 | 'molecular physics'], 79 | tests_require=['tox', 'pytest'], 80 | cmdclass={'test': Tox}, 81 | ) 82 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | # Byte-compiled / optimized / DLL files 3 | __pycache__/ 4 | *.py[cod] 5 | *$py.class 6 | 7 | # C extensions 8 | *.so 9 | 10 | # Distribution / packaging 11 | .Python 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | pip-wheel-metadata/ 25 | share/python-wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | MANIFEST 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .nox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | *.py,cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | cover/ 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | db.sqlite3 63 | db.sqlite3-journal 64 | 65 | # Flask stuff: 66 | instance/ 67 | .webassets-cache 68 | 69 | # Scrapy stuff: 70 | .scrapy 71 | 72 | # Sphinx documentation 73 | docs/_build/ 74 | 75 | # PyBuilder 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | # pytype static type analyzer 135 | .pytype/ 136 | -------------------------------------------------------------------------------- /tests/test_basisset/test_basisset_json_io.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | from chemtools.basisset import BasisSet 4 | 5 | 6 | VTZGAUSSIAN = """ 7 | **** 8 | Be 0 9 | S 11 1.00 10 | 6863.0000000000 0.00023600 11 | 1030.0000000000 0.00182600 12 | 234.7000000000 0.00945200 13 | 66.5600000000 0.03795700 14 | 21.6900000000 0.11996500 15 | 7.7340000000 0.28216200 16 | 2.9160000000 0.42740400 17 | 1.1300000000 0.26627800 18 | 0.2577000000 0.01819300 19 | 0.1101000000 -0.00727500 20 | 0.0440900000 0.00190300 21 | S 11 1.00 22 | 6863.0000000000 -0.00004300 23 | 1030.0000000000 -0.00033300 24 | 234.7000000000 -0.00173600 25 | 66.5600000000 -0.00701200 26 | 21.6900000000 -0.02312600 27 | 7.7340000000 -0.05813800 28 | 2.9160000000 -0.11455600 29 | 1.1300000000 -0.13590800 30 | 0.2577000000 0.22802600 31 | 0.1101000000 0.57744100 32 | 0.0440900000 0.31787300 33 | S 1 1.00 34 | 0.2577000000 1.00000000 35 | S 1 1.00 36 | 0.0440900000 1.00000000 37 | P 5 1.00 38 | 7.4360000000 0.01073600 39 | 1.5770000000 0.06285400 40 | 0.4352000000 0.24818000 41 | 0.1438000000 0.52369900 42 | 0.0499400000 0.35342500 43 | P 1 1.00 44 | 0.1438000000 1.00000000 45 | P 1 1.00 46 | 0.0499400000 1.00000000 47 | D 1 1.00 48 | 0.3493000000 1.00000000 49 | D 1 1.00 50 | 0.1724000000 1.00000000 51 | F 1 1.00 52 | 0.3423000000 1.00000000 53 | **** 54 | """ 55 | 56 | 57 | def ordered(obj): 58 | if isinstance(obj, dict): 59 | return sorted((k, ordered(v)) for k, v in obj.items()) 60 | if isinstance(obj, list): 61 | return sorted(ordered(x) for x in obj) 62 | else: 63 | return obj 64 | 65 | 66 | def test_to_json(): 67 | 68 | bs = BasisSet.from_str(VTZGAUSSIAN, fmt='gaussian', name='VTZ') 69 | 70 | bsdumped = bs.to_json(indent=4) 71 | bsloaded = BasisSet.from_json(bsdumped) 72 | 73 | assert bs.name == bsloaded.name, 'inconsistent name' 74 | assert bs.element == bsloaded.element, 'inconsistent element' 75 | 76 | for shell, funs in bs.functions.items(): 77 | 78 | assert shell in bsloaded.functions.keys(), 'missing shell {}'.format(shell) 79 | 80 | assert np.allclose(funs['e'], bsloaded.functions[shell]['e']) 81 | 82 | for f1, f2 in zip(funs['cf'], bsloaded.functions[shell]['cf']): 83 | assert np.allclose(f1['idx'], f2['idx']), 'inconsistent idx' 84 | assert np.allclose(f1['cc'], f2['cc']), 'inconsistent cc' 85 | -------------------------------------------------------------------------------- /tests/test_basisopt/test_dalton_aug_BeH-.py: -------------------------------------------------------------------------------- 1 | from chemtools.basisopt import BSOptimizer 2 | from chemtools.molecule import Molecule 3 | from chemtools.calculators.dalton import Dalton 4 | from chemtools.basisset import BasisSet 5 | import pytest 6 | import os 7 | 8 | 9 | @pytest.mark.skipif(os.getenv('DALTON_EXE') is None, 10 | reason=" undefined") 11 | def test_optimize(tmpdir): 12 | 13 | tmpdir.chdir() 14 | 15 | dalton = Dalton(exevar='DALTON_EXE', 16 | runopts=['-nobackup', '-noarch', '-d']) 17 | 18 | beh = Molecule(name="BeH-", atoms=[('Be',), ('H', (0.0, 0.0, 2.724985))], 19 | sym="cnv 2", charge=-1, multiplicity=1) 20 | 21 | moltemplate = '''INTGRL 22 | basis set optimization 23 | test dalton calculator 24 | Atomtypes=2 Charge=-1 Integrals=1.0D-20 25 | %basis 26 | ''' 27 | 28 | hftemplate = '''**DALTON INPUT 29 | .RUN WAVE FUNCTIONS 30 | **WAVE FUNCTION 31 | .HF 32 | **END OF DALTON INPUT 33 | ''' 34 | 35 | fname = {'dal': 'hf.dal', 'mol': 'BeH-.mol'} 36 | template = {'mol': moltemplate, 'dal': hftemplate} 37 | 38 | optimization = {"method": "Nelder-Mead", 39 | "tol": 1.0e-4, 40 | "options": {"maxiter": 100, 41 | "disp": True} 42 | } 43 | 44 | ccpvdz_str = '''basis={ 45 | s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02; 46 | c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03; 47 | c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01; 48 | c,9.9,1.000000E+00; 49 | 50 | p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02; 51 | c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01; 52 | c,4.4,1.000000E+00; 53 | 54 | d,Be,2.354000E-01; 55 | c,1.1,1.000000E+00; 56 | 57 | s, H , 13.0100000, 1.9620000, 0.4446000, 0.1220000, 0.0297400 58 | c, 1.3, 0.0196850, 0.1379770, 0.4781480 59 | c, 4.4, 1 60 | c, 5.5, 1 61 | p, H , 0.7270000, 0.1410000 62 | c, 1.1, 1 63 | c, 2.2, 1 64 | } 65 | ''' 66 | 67 | ccpvdz = BasisSet.from_str(ccpvdz_str, fmt='molpro') 68 | 69 | augfs = {'Be': [('s', 'exp', 1, (0.02,)), 70 | ('p', 'exp', 1, (0.01,)), 71 | ('d', 'exp', 1, (0.07,))]} 72 | 73 | bso = BSOptimizer(objective='hf total energy', template=template, 74 | code=dalton, mol=beh, 75 | fsopt=augfs, staticbs=ccpvdz, verbose=True, 76 | optalg=optimization, fname=fname) 77 | 78 | bso.run() 79 | 80 | energy = -15.131589405116999 81 | assert abs(bso.result.fun - energy) < 1.0e-8, 'wrong objective' 82 | -------------------------------------------------------------------------------- /tests/test_basisopt/test_psi4_exps_aug_BeH-.py: -------------------------------------------------------------------------------- 1 | from chemtools.basisopt import BSOptimizer 2 | from chemtools.molecule import Molecule 3 | from chemtools.calculators.psi4 import Psi4 4 | from chemtools.basisset import BasisSet 5 | import pytest 6 | import os 7 | 8 | 9 | @pytest.mark.skipif(os.getenv('PSI4_EXE') is None, 10 | reason=" undefined") 11 | def test_optimize(tmpdir): 12 | 13 | tmpdir.chdir() 14 | 15 | psi = Psi4(exevar="PSI4_EXE", runopts=["-n", "4"]) 16 | 17 | beh = Molecule(name="BeH-", atoms=[('Be',), ('H', (0.0, 0.0, 2.724985))], 18 | sym="cnv 2", charge=-1, multiplicity=1) 19 | 20 | psitemp = '''#! test BeH- 21 | 22 | memory 100 mb 23 | 24 | molecule beh { 25 | Be 0.0000 0.0000 0.0000 26 | H 0.0000 0.0000 1.4420 27 | units angstrom 28 | } 29 | 30 | beh.set_molecular_charge(-1) 31 | beh.set_multiplicity(1) 32 | 33 | 34 | basis = { 35 | 36 | assign mybasis 37 | 38 | [ mybasis ] 39 | spherical 40 | 41 | %basisset 42 | 43 | } 44 | 45 | set { 46 | freeze_core True 47 | e_convergence 13 48 | d_convergence 10 49 | } 50 | 51 | energy('cisd') 52 | ''' 53 | 54 | optimization = {"method": "Nelder-Mead", 55 | "tol": 1.0e-4, 56 | "options": {"maxiter": 100, 57 | "disp": True, 58 | } 59 | } 60 | 61 | ccpvdz_str = '''basis={ 62 | s,Be,2.940000E+03,4.412000E+02,1.005000E+02,2.843000E+01,9.169000E+00,3.196000E+00,1.159000E+00,1.811000E-01,5.890000E-02; 63 | c,1.9,6.800000E-04,5.236000E-03,2.660600E-02,9.999300E-02,2.697020E-01,4.514690E-01,2.950740E-01,1.258700E-02,-3.756000E-03; 64 | c,1.9,-1.230000E-04,-9.660000E-04,-4.831000E-03,-1.931400E-02,-5.328000E-02,-1.207230E-01,-1.334350E-01,5.307670E-01,5.801170E-01; 65 | c,9.9,1.000000E+00; 66 | 67 | p,Be,3.619000E+00,7.110000E-01,1.951000E-01,6.018000E-02; 68 | c,1.4,2.911100E-02,1.693650E-01,5.134580E-01,4.793380E-01; 69 | c,4.4,1.000000E+00; 70 | 71 | d,Be,2.354000E-01; 72 | c,1.1,1.000000E+00; 73 | 74 | s, H , 13.0100000, 1.9620000, 0.4446000, 0.1220000, 0.0297400 75 | c, 1.3, 0.0196850, 0.1379770, 0.4781480 76 | c, 4.4, 1 77 | c, 5.5, 1 78 | p, H , 0.7270000, 0.1410000 79 | c, 1.1, 1 80 | c, 2.2, 1 81 | } 82 | ''' 83 | 84 | ccpvdz = BasisSet.from_str(ccpvdz_str, fmt='molpro') 85 | 86 | augfs = {'Be': [('s', 'exp', 1, (0.02,)), 87 | ('p', 'exp', 1, (0.01,)), 88 | ('d', 'exp', 1, (0.07,))]} 89 | 90 | bso = BSOptimizer(objective='cisd total energy', template=psitemp, 91 | code=psi, mol=beh, fsopt=augfs, staticbs=ccpvdz, 92 | core=[1, 0, 0, 0, 0, 0, 0, 0], verbose=True, 93 | optalg=optimization, fname='beh_aug.dat') 94 | 95 | bso.run() 96 | 97 | energy = -15.204232302468 98 | assert abs(bso.result.fun - energy) < 1.0e-8, 'wrong objective' 99 | -------------------------------------------------------------------------------- /tests/test_gamessus/test_SequentialFile.py: -------------------------------------------------------------------------------- 1 | 2 | import unittest 3 | from chemtools.calculators.gamessreader import SequentialFile 4 | import os 5 | import numpy as np 6 | 7 | 8 | class TestSequentialFileHeMini(unittest.TestCase): 9 | 10 | def setUp(self): 11 | seqfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 12 | 'data/he/he_mini_hf.F08') 13 | self.seq = SequentialFile(seqfile) 14 | 15 | def tearDown(self): 16 | self.seq.file.close() 17 | 18 | def test_read_irect_he(self): 19 | ints = np.array([0.12856711538353], dtype=float) 20 | self.assertTrue(np.allclose(self.seq.readseq(), ints)) 21 | 22 | 23 | class TestSequentialFileNeDZAO(unittest.TestCase): 24 | 25 | def setUp(self): 26 | seqfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 27 | 'data/ne/ne_dz_guga.F08') 28 | self.seq = SequentialFile(seqfile) 29 | 30 | def tearDown(self): 31 | self.seq.file.close() 32 | 33 | def test_read_ao_integrals_ne(self): 34 | ints = np.load(os.path.join(os.path.abspath(os.path.dirname(__file__)), 35 | 'data/ne/ne_dz_guga_aoints.npy')) 36 | self.assertTrue(np.allclose(self.seq.readseq(), ints)) 37 | 38 | 39 | class TestSequentialFileNeDZMO(unittest.TestCase): 40 | 41 | def setUp(self): 42 | seqfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 43 | 'data/ne/ne_dz_guga.F09') 44 | self.seq = SequentialFile(seqfile) 45 | 46 | def tearDown(self): 47 | self.seq.file.close() 48 | 49 | def test_read_mo_one_electron_integrals_ne(self): 50 | #ints = np.load(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data/ne/ne_dz_guga_moints.npy')) 51 | #self.assertTrue(np.allclose(self.seq.readseq(mos=True), ints)) 52 | pass 53 | 54 | def test_read_mo_two_electron_integrals_ne(self): 55 | ints = np.load(os.path.join(os.path.abspath(os.path.dirname(__file__)), 56 | 'data/ne/ne_dz_guga_moints.npy')) 57 | self.assertTrue(np.allclose(self.seq.readseq(mos=True, skip_first=True), ints)) 58 | 59 | 60 | class TestSequentialFileNeDZ2RDM(unittest.TestCase): 61 | 62 | def setUp(self): 63 | seqfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 64 | 'data/ne/ne_dz_guga.F15') 65 | self.seq = SequentialFile(seqfile) 66 | 67 | def tearDown(self): 68 | self.seq.file.close() 69 | 70 | def test_read_two_particle_density_matrix_ne(self): 71 | ints = np.load(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data/ne/ne_dz_guga_rdm2.npy')) 72 | self.assertTrue(np.allclose(self.seq.readseq(mos=True, skip_first=False), ints)) 73 | 74 | 75 | if __name__ == "__main__": 76 | unittest.main() 77 | -------------------------------------------------------------------------------- /examples/BasisSetClass/h_av6z.bas: -------------------------------------------------------------------------------- 1 | {u'status': u'published', u'functions': {u'd': {u'contractedfs': [{u'indices': [0], u'coefficients': [1.0]}, {u'indices': [1], u'coefficients': [1.0]}, {u'indices': [2], u'coefficients': [1.0]}, {u'indices': [3], u'coefficients': [1.0]}, {u'indices': [4], u'coefficients': [1.0]}], u'exponents': [4.453, 1.958, 0.861, 0.378, 0.126]}, u'g': {u'contractedfs': [{u'indices': [0], u'coefficients': [1.0]}, {u'indices': [1], u'coefficients': [1.0]}, {u'indices': [2], u'coefficients': [1.0]}], u'exponents': [3.199, 1.326, 0.407]}, u'f': {u'contractedfs': [{u'indices': [0], u'coefficients': [1.0]}, {u'indices': [1], u'coefficients': [1.0]}, {u'indices': [2], u'coefficients': [1.0]}, {u'indices': [3], u'coefficients': [1.0]}], u'exponents': [4.1, 1.78, 0.773, 0.245]}, u'h': {u'contractedfs': [{u'indices': [0], u'coefficients': [1.0]}, {u'indices': [1], u'coefficients': [1.0]}], u'exponents': [2.653, 0.682]}, u'p': {u'contractedfs': [{u'indices': [0], u'coefficients': [1.0]}, {u'indices': [1], u'coefficients': [1.0]}, {u'indices': [2], u'coefficients': [1.0]}, {u'indices': [3], u'coefficients': [1.0]}, {u'indices': [4], u'coefficients': [1.0]}, {u'indices': [5], u'coefficients': [1.0]}], u'exponents': [8.649, 3.43, 1.36, 0.539, 0.214, 0.067]}, u's': {u'contractedfs': [{u'indices': [0, 1, 2, 3, 4], u'coefficients': [4.4e-05, 0.000372, 0.002094, 0.008863, 0.03054]}, {u'indices': [5], u'coefficients': [1.0]}, {u'indices': [6], u'coefficients': [1.0]}, {u'indices': [7], u'coefficients': [1.0]}, {u'indices': [8], u'coefficients': [1.0]}, {u'indices': [9], u'coefficients': [1.0]}, {u'indices': [10], u'coefficients': [1.0]}], u'exponents': [1776.77556, 254.017712, 54.698039, 15.018344, 4.915078, 1.794924, 0.710716, 0.304802, 0.138046, 0.062157, 0.0189]}}, u'type': u'orbital', u'name': u'aug-cc-pV6Z', u'lastModified': u'Mon, 15 Jan 2007 23:46:09 GMT', u'url': u'https://bse.pnl.gov:443/bse/portal/user/anon/js_peid/11535052407933/action/portlets.BasisSetAction/template/courier_content/panel/Main/eventSubmit_doDownload/true?bsurl=/files/projects/Basis_Set_Curators/Gaussian/emsl-lib/AUG-CC-PV6Z-AGG.xml&bsname=aug-cc-pV6Z&elts=H+He+B+C+N+O+F+Ne+Al+Si+P+S+Cl+Ar&format=Molpro&minimize=true', u'contributorName': u'Dr. David Feller', u'hasSpin': False, u'addedBy': {u'email': u'lmmentel@gmail.com', u'name': u'Lukasz Mentel'}, u'element': u'H', u'contributionPI': u'N/A', u'ecp': u'N/A', u'hasECP': False, u'_id': ObjectId('53b1252613094f3a1584bef6'), u'publishedIn': u'! H: K.A. Peterson, D.E. Woon and T. H. Dunning, Jr., (to be published).\n! B - Ne: A. K. Wilson, T. v. Mourik and T. H. Dunning, Jr., J. Mol. Struct.\n! (THEOCHEM) 388, 339 (1997).\n! S: J.G. Hill, S. Mazumder, and K.A. Peterson, Correlation consistent basis sets for molecular core-valence effects with explicitly correlated wave functions: the atoms B-Ne and Al-Ar, Journal of Chemical Physics 132, 054108 (2010).\n', u'bsAbstract': u'V6Z5P Valence Sextuple Zeta + Polarization + Diffuse'} 2 | -------------------------------------------------------------------------------- /tests/test_basisopt/test_shell_optimization.py: -------------------------------------------------------------------------------- 1 | 2 | from chemtools.molecule import Molecule 3 | from chemtools.calculators import molpro 4 | from chemtools.basisopt import opt_shell_by_nf, opt_multishell 5 | import pytest 6 | 7 | 8 | @pytest.fixture 9 | def be2(): 10 | return Molecule(name="Be2", atoms=[("Be", (0.0, 0.0, 1.2268016705), False), 11 | ("Be", (0.0, 0.0, -1.2268016705), False)], 12 | charge=0, multiplicity=1) 13 | 14 | 15 | @pytest.fixture 16 | def be_atom(): 17 | return Molecule(name="Be", atoms=[("Be", (0.0, 0.0, 0.0), False)], 18 | charge=0, multiplicity=1) 19 | 20 | 21 | @pytest.fixture 22 | def optimization(): 23 | return { 24 | "method": "Nelder-Mead", 25 | "lambda": 10.0, 26 | "tol": 1.0e-3, 27 | "options": {"maxiter": 500, 28 | "disp": True} 29 | } 30 | 31 | 32 | @pytest.fixture 33 | def calculator(): 34 | return molpro.Molpro(exevar="MOLPRO_EXE", 35 | runopts=["-s", "-n", "4", "-d", "."]) 36 | 37 | 38 | @pytest.mark.skip(reason="no way of currently testing this") 39 | def test_optimize_s(calculator, optimization, be): 40 | 41 | job = {"method": "hf", 42 | "objective": "total energy", 43 | "core": [0, 0, 0, 0, 0, 0, 0, 0], 44 | "inpname": "be_hf.inp", 45 | "inpdata": '', 46 | "verbose": True, 47 | } 48 | 49 | nfs = range(2, 20) 50 | bsopt = {"typ": "legendre", 51 | "name": "nowa baza", 52 | "kind": "hf", 53 | "params": [(1.37, 2.83, 0.4)], 54 | "element": "Be"} 55 | 56 | opt_shell_by_nf(shell='s', 57 | nfs=nfs, 58 | max_params=5, 59 | opt_tol=1.0e-2, 60 | save=True, 61 | code=calculator, 62 | job=job, 63 | mol=be, 64 | bsnoopt=None, 65 | bsopt=bsopt, 66 | opt=optimization) 67 | 68 | 69 | @pytest.mark.skip(reason="no way of currently testing this") 70 | def test_optimize_multishell(calculator, optimization, be2): 71 | 72 | shells = ['s', 'p', 'd'] 73 | nfps = [range(4, 15), range(1, 10), range(1, 5)] 74 | guesses = [[1.37, 2.83, -0.4, 0.3], [2.5], [0.5]] 75 | 76 | bsopt = {"typ": "legendre", 77 | "name": "nowa baza", 78 | "kind": "hf", 79 | "element": "Be"} 80 | 81 | job = {"method": "hf", 82 | "objective": "total energy", 83 | "core": [0, 0, 0, 0, 0, 0, 0, 0], 84 | "inpname": "be_hf.inp", 85 | "inpdata": '', 86 | "verbose": True, 87 | } 88 | 89 | # "params" : [(1.37, 2.83, -0.4, 0.3),], 90 | opt_multishell(shells=shells, nfps=nfps, guesses=guesses, max_params=5, 91 | opt_tol=1.0e-3, 92 | save=True, bsopt=bsopt, 93 | code=calculator, 94 | job=job, 95 | mol=be2, 96 | bsnoopt=None, 97 | opt=optimization) 98 | -------------------------------------------------------------------------------- /doc/source/api.rst: -------------------------------------------------------------------------------- 1 | .. _api: 2 | 3 | ************* 4 | API Reference 5 | ************* 6 | 7 | Calculators 8 | =========== 9 | 10 | .. _calculator-class: 11 | 12 | Base Calculator 13 | --------------- 14 | 15 | .. currentmodule:: chemtools.calculators.calculator 16 | 17 | .. autoclass:: Calculator 18 | :members: 19 | 20 | .. _dalton-class: 21 | 22 | Dalton 23 | ------ 24 | 25 | .. currentmodule:: chemtools.calculators.dalton 26 | 27 | .. autoclass:: Dalton 28 | :members: 29 | 30 | .. _dmft-class: 31 | 32 | DMFT 33 | ---- 34 | 35 | .. currentmodule:: chemtools.calculators.dmft 36 | 37 | .. autoclass:: Dmft 38 | :members: 39 | 40 | .. _gamessus-class: 41 | 42 | GAMESS-US 43 | --------- 44 | 45 | .. currentmodule:: chemtools.calculators.gamessus 46 | 47 | .. autoclass:: GamessUS 48 | :members: 49 | 50 | .. _molpro-class: 51 | 52 | Molpro 53 | ------ 54 | 55 | .. currentmodule:: chemtools.calculators.molpro 56 | 57 | .. autoclass:: Molpro 58 | :members: 59 | 60 | .. _psi4-class: 61 | 62 | PSI4 63 | ---- 64 | 65 | .. currentmodule:: chemtools.calculators.psi4 66 | 67 | .. autoclass:: Psi4 68 | :members: 69 | 70 | Basis Set Tools 71 | =============== 72 | 73 | .. _basisset-class: 74 | 75 | BasisSet module 76 | --------------- 77 | 78 | .. currentmodule:: chemtools.basisset 79 | 80 | .. autoclass:: BasisSet 81 | :members: 82 | 83 | 84 | .. autofunction:: has_consecutive_indices 85 | 86 | .. autofunction:: reorder_shell_to_consecutive 87 | 88 | .. autofunction:: merge 89 | 90 | .. autofunction:: primitive_overlap 91 | 92 | .. autofunction:: nspherical 93 | 94 | .. autofunction:: ncartesian 95 | 96 | .. autofunction:: zetas2legendre 97 | 98 | .. autofunction:: zetas2eventemp 99 | 100 | .. autofunction:: eventemp 101 | 102 | .. autofunction:: welltemp 103 | 104 | .. autofunction:: legendre 105 | 106 | .. autofunction:: xyzlist 107 | 108 | .. autofunction:: zlmtoxyz 109 | 110 | .. _basisparse-module: 111 | 112 | basisparse module 113 | ----------------- 114 | 115 | Parsing basis set from different formats. 116 | 117 | .. automodule:: chemtools.basisparse 118 | :members: 119 | 120 | 121 | basisopt module 122 | --------------- 123 | 124 | Optimization of basis set exponents and contraction coefficients. 125 | 126 | .. automodule:: chemtools.basisopt 127 | :members: 128 | 129 | CBS module 130 | ---------- 131 | 132 | Complete Basis Set (CBS) extrapolation techniques. 133 | 134 | .. automodule:: chemtools.cbs 135 | :members: 136 | 137 | Molecule module 138 | --------------- 139 | 140 | .. automodule:: chemtools.molecule 141 | :members: 142 | 143 | parsetools module 144 | ----------------- 145 | 146 | .. automodule:: chemtools.parsetools 147 | :members: 148 | 149 | submitgamess module 150 | ------------------- 151 | 152 | .. automodule:: chemtools.submitgamess 153 | :members: 154 | 155 | submitmolpro module 156 | ------------------- 157 | 158 | .. automodule:: chemtools.submitmolpro 159 | :members: 160 | 161 | gamessorbitals module 162 | --------------------- 163 | 164 | .. automodule:: chemtools.calculators.gamessorbitals 165 | :members: 166 | 167 | gamessreader module 168 | ------------------- 169 | 170 | .. automodule:: chemtools.calculators.gamessreader 171 | :members: 172 | -------------------------------------------------------------------------------- /chemtools/cli.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import print_function 4 | 5 | from argparse import ArgumentParser 6 | import os 7 | import sys 8 | 9 | from chemtools.basisset import BasisSet 10 | 11 | 12 | def bsprint(): 13 | ''' 14 | CLI script to read a basis set from a file in internal format and print 15 | in a specified format 16 | ''' 17 | 18 | parser = ArgumentParser() 19 | parser.add_argument("file", 20 | help="file name with a pickled BasisSet object") 21 | parser.add_argument("-f", "--format", 22 | choices=["cfour", "dalton", "gamessus", "gaussian", 23 | "json", "molpro", "nwchem"], 24 | default="default") 25 | args = parser.parse_args() 26 | 27 | bs = BasisSet.from_pickle(args.file) 28 | 29 | if args.format == 'default': 30 | print(str(bs)) 31 | else: 32 | writer = "to_" + args.format 33 | method = getattr(bs, writer) 34 | print(method()) 35 | 36 | 37 | def bsconvert(): 38 | ''' 39 | CLI script to convert between different basis set formats 40 | ''' 41 | 42 | parser = ArgumentParser(description='Convert basis set between formats of different programs') 43 | parser.add_argument("filename", 44 | help="file name with a basis set, default='pickle'") 45 | parser.add_argument("-from", 46 | "--inputformat", 47 | choices=["gamessus", "gaussian", "json", "molpro", 48 | "pickle"], 49 | help="Basis set input format", 50 | default="pickle") 51 | parser.add_argument("-to", 52 | "--outputformat", 53 | choices=["cfour", "dalton", "gamessus", "gaussian", 54 | "json", "molpro", "nwchem", "pickle"], 55 | help="Basis set output format", 56 | default="molpro") 57 | parser.add_argument('-o', '--output', help='name of the output file') 58 | args = parser.parse_args() 59 | 60 | name = os.path.splitext(args.filename)[0] 61 | 62 | if args.inputformat == "pickle": 63 | bsets = BasisSet.from_pickle(args.filename) 64 | elif args.inputformat == "json": 65 | bsets = BasisSet.from_json(args.filename) 66 | else: 67 | bsets = BasisSet.from_file(fname=args.filename, fmt=args.inputformat, 68 | name=name) 69 | 70 | if args.outputformat == "pickle": 71 | if isinstance(bsets, dict): 72 | for elem, bset in bsets.items(): 73 | bset.to_pickle(name + '_' + elem + '.pkl') 74 | elif isinstance(bsets, BasisSet): 75 | bsets.to_pickle(name + '_' + bsets.element + '.pkl') 76 | else: 77 | writer_name = "to_" + args.outputformat 78 | writer_objs = [] 79 | if isinstance(bsets, dict): 80 | for elem, bset in bsets.items(): 81 | writer_objs.append(getattr(bset, writer_name)) 82 | elif isinstance(bsets, BasisSet): 83 | writer_objs.append(getattr(bsets, writer_name)) 84 | else: 85 | raise ValueError('Something went wrong') 86 | 87 | if args.output: 88 | fobj = open(args.output, 'w') 89 | else: 90 | fobj = sys.stdout 91 | 92 | for writer in writer_objs: 93 | print(writer(), file=fobj) 94 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | ===================================================== 2 | chemtools: Python toolbox for Computational Chemistry 3 | ===================================================== 4 | 5 | Chemtools is a set of modules that is intended to help with more 6 | advanced computations using common electronic structure programs. 7 | 8 | The main to goal was to enable convenient `basis set `_ manipulations, including designing and optimizing exponents of basis sets. To achieve that there are several modules abstracting various functionalities: 9 | 10 | Basis set object 11 | :mod:`basisset ` module that contains the :class:`chemtools.basisset.BasisSet`. See the :doc:`tutorial` page for a overview 12 | of the capabilities. 13 | 14 | Basis set optimization 15 | :mod:`basisopt ` module that contains functionalities 16 | for building up basis set optimization tasks. See the :doc:`tutorial` 17 | page for a few illustrative examples. 18 | 19 | Calculators 20 | :mod:`chemtools.calculators.calculator` contains wrappers for several packages 21 | handling the actual electronic structure calculations. Currently there is support for: 22 | 23 | * Dalton_ 24 | * Gamess-US_ 25 | * MolPro_ 26 | * PSI4_ 27 | 28 | Molecule 29 | :mod:`chemtools.molecule` is general purpose module intorducing molecule class 30 | for handling molecules and defining atomic compositions and molecular geometries 31 | 32 | Complete basis set extrapolation 33 | :mod:`chemtools.cbs` contains functions for performing complete basis set (CBS) extrapolation using different approaches. 34 | 35 | 36 | Contents 37 | ======== 38 | 39 | .. toctree:: 40 | :maxdepth: 2 41 | 42 | Installation 43 | Tutorials 44 | API Reference 45 | 46 | 47 | Contributing 48 | ============ 49 | 50 | * `Source `_ 51 | * `Report a bug `_ 52 | * `Request a feature `_ 53 | * `Submit a pull request `_ 54 | 55 | Contact 56 | ======= 57 | 58 | Łukasz Mentel 59 | 60 | * github: `lmmentel `_ 61 | * email: lmmentel gmail.com 62 | 63 | 64 | Citing 65 | ====== 66 | 67 | If you use *chemtools* in a scientific publication, please consider citing the software as 68 | 69 | Łukasz Mentel, *chemtools* -- A Python toolbox for computational chemistry, 2014-- . Available at: `https://github.com/lmmentel/chemtools `_. 70 | 71 | 72 | Here's the reference in the `BibLaTeX `_ format 73 | 74 | .. code-block:: latex 75 | 76 | @software{chemtools2014, 77 | author = {Mentel, Łukasz}, 78 | title = {{chemtools} -- A Python toolbox for computational chemistry}, 79 | url = {https://github.com/lmmentel/chemtools}, 80 | version = {0.9.2}, 81 | date = {2014--}, 82 | } 83 | 84 | or the older `BibTeX `_ format 85 | 86 | .. code-block:: latex 87 | 88 | @misc{chemtools2014, 89 | auhor = {Mentel, Łukasz}, 90 | title = {{chemtools} -- A Python toolbox for computational chemistry, ver. 0.9.2}, 91 | howpublished = {\url{https://github.com/lmmentel/chemtools}}, 92 | year = {2014--}, 93 | } 94 | 95 | Funding 96 | ======= 97 | 98 | This project was realized through the support from the National Science Center 99 | (Poland) grant number UMO-2012/07/B/ST4/01347. 100 | 101 | Related projects 102 | ================ 103 | 104 | `cclib `_ 105 | A python library for parsing 106 | 107 | `pygamess `_ 108 | Python wrapper for Gamess(US) 109 | 110 | 111 | License 112 | ======= 113 | 114 | .. include:: ../../LICENSE.rst 115 | 116 | 117 | Indices and tables 118 | ================== 119 | * :ref:`genindex` 120 | * :ref:`modindex` 121 | * :ref:`search` 122 | 123 | 124 | .. _DALTON: http://daltonprogram.org/ 125 | .. _Gamess-US: http://www.msg.ameslab.gov/gamess 126 | .. _MolPro: http://www.molpro.net/ 127 | .. _PSI4: http://www.psicode.org/ 128 | -------------------------------------------------------------------------------- /chemtools/calculators/dmft.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | from chemtools.calculators.calculator import Calculator 26 | from chemtools.calculators.gamessus import GamessLogParser 27 | from subprocess import Popen 28 | 29 | import os 30 | 31 | 32 | class Dmft(Calculator): 33 | 34 | '''dmft class''' 35 | 36 | def __init__(self, logfile): 37 | 38 | ''' 39 | Initialize the dmft class object, logfile is the gamess log file name. 40 | ''' 41 | 42 | super(Dmft, self).__init__(**kwargs) 43 | self.logfile = logfile 44 | 45 | def write_input(self, functional=None, a1=None, b1=None, a2=None, b2=None, printlevel=None, analyze=None): 46 | 47 | '''Write dmft input based on information in the gamess log file.''' 48 | 49 | inputdata = self.parse_gamess() 50 | 51 | if functional: 52 | inputdata["functional"] = functional 53 | if a1: 54 | inputdata["a1"] = a1 55 | if b1: 56 | inputdata["b1"] = b1 57 | if a2: 58 | inputdata["a2"] = a2 59 | if b2: 60 | inputdata["b2"] = b2 61 | if printlevel: 62 | inputdata["print_level"] = printlevel 63 | if analyze: 64 | inputdata["analyze"] = ".true." 65 | 66 | filebase = "dmft_fun{0:`_ manipulations, including designing and optimizing exponents of basis sets. To achieve that there are several modules abstracting various functionalities. 30 | 31 | Currently there is support optimizing basis set (or doing general computations) with: 32 | 33 | * Dalton_ 34 | * Gamess-US_ 35 | * MolPro_ 36 | * PSI4_ 37 | 38 | 39 | Table of Contents 40 | ================= 41 | 42 | * `Getting Started`_ 43 | 44 | * Installation_ 45 | * Documentation_ 46 | 47 | * Contributing_ 48 | * Contact_ 49 | * Citing_ 50 | * Funding_ 51 | * License_ 52 | 53 | Getting Started 54 | =============== 55 | 56 | The best way to get started is to go over the `tutorials `_ illustrating the functionalities and giving examples of basis set optimization tasks. 57 | 58 | Installation 59 | ------------ 60 | 61 | Most convenient way to install the package is with `pip `_ 62 | 63 | .. code-block:: bash 64 | 65 | pip install chemtools 66 | 67 | 68 | Documentation 69 | ------------- 70 | 71 | The documentation in hosted at `Read The Docs `_. 72 | 73 | 74 | Contributing 75 | ============ 76 | 77 | * `Source `_ 78 | * `Report a bug `_ 79 | * `Request a feature `_ 80 | * `Submit a pull request `_ 81 | 82 | Contact 83 | ======= 84 | 85 | Łukasz Mentel 86 | 87 | * github: `lmmentel `_ 88 | * email: lmmentel gmail.com 89 | 90 | 91 | Citing 92 | ====== 93 | 94 | If you use *chemtools* in a scientific publication, please consider citing the software as 95 | 96 | Łukasz Mentel, *chemtools* -- A Python toolbox for computational chemistry, 2014-- . Available at: `https://github.com/lmmentel/chemtools `_. 97 | 98 | 99 | Here's the reference in the `BibLaTeX `_ format 100 | 101 | .. code-block:: latex 102 | 103 | @software{chemtools2014, 104 | author = {Mentel, Łukasz}, 105 | title = {{chemtools} -- A Python toolbox for computational chemistry}, 106 | url = {https://github.com/lmmentel/chemtools}, 107 | version = {0.9.2}, 108 | date = {2014--}, 109 | } 110 | 111 | or the older `BibTeX `_ format 112 | 113 | .. code-block:: latex 114 | 115 | @misc{chemtools2014, 116 | auhor = {Mentel, Łukasz}, 117 | title = {{chemtools} -- A Python toolbox for computational chemistry, ver. 0.9.2}, 118 | howpublished = {\url{https://github.com/lmmentel/chemtools}}, 119 | year = {2014--}, 120 | } 121 | 122 | Funding 123 | ======= 124 | 125 | This project was realized through the support from the National Science Center 126 | (Poland) grant number UMO-2012/07/B/ST4/01347. 127 | 128 | License 129 | ======= 130 | 131 | The project is distributed under the MIT License. See `LICENSE `_ for more information. 132 | 133 | .. _chemtools: http://chemtools.readthedocs.org 134 | .. _Gamess-US: https://www.msg.chem.iastate.edu/gamess/gamess.html 135 | .. _MolPro: http://www.molpro.net/ 136 | .. _Dalton: https://www.daltonprogram.org/ 137 | .. _PSI4: http://www.psicode.org/ 138 | -------------------------------------------------------------------------------- /tests/test_cbs/test_cbs.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from scipy.optimize import curve_fit 3 | 4 | from chemtools import cbs 5 | 6 | 7 | class TestPoly(unittest.TestCase): 8 | 9 | def setUp(self): 10 | # VO Be_2 VXZ corr energies at R_e 11 | self.x = [2, 3, 4, 5, 6] 12 | self.ens = [-0.1006245329, -0.1047828536, -0.1062511383, -0.1066997691, 13 | -0.1068704347] 14 | 15 | def tearDown(self): 16 | del self.x 17 | del self.ens 18 | 19 | def test_poly_2point_default(self): 20 | f = cbs.poly() 21 | eopt, ecov = curve_fit(f, self.x[-2:], self.ens[-2:]) 22 | self.assertAlmostEqual(-0.1071048655, eopt[0]) 23 | 24 | def test_poly_3point(self): 25 | f = cbs.poly(twopoint=False) 26 | eopt, ecov = curve_fit(f, self.x[-3:], self.ens[-3:]) 27 | self.assertAlmostEqual(-0.1070460458, eopt[0]) 28 | 29 | 30 | class TestExpo(unittest.TestCase): 31 | 32 | def setUp(self): 33 | self.x = [2, 3, 4, 5, 6] 34 | self.ens = [-29.1322987785, -29.1337749163, -29.1340309055, 35 | -29.1341443009, -29.1341692835] 36 | self.f = cbs.expo() 37 | 38 | def tearDown(self): 39 | del self.x 40 | del self.ens 41 | 42 | def test_expo_3point(self): 43 | eopt, ecov = curve_fit(self.f, self.x[2:], self.ens[2:]) 44 | self.assertAlmostEqual(-29.1341763428, eopt[0]) 45 | 46 | def test_expo_4point(self): 47 | eopt, ecov = curve_fit(self.f, self.x[1:], self.ens[1:]) 48 | self.assertAlmostEqual(-29.1341981701, eopt[0]) 49 | 50 | def test_expo_5point(self): 51 | eopt, ecov = curve_fit(self.f, self.x, self.ens) 52 | self.assertAlmostEqual(-29.1341546294, eopt[0]) 53 | 54 | 55 | class TestExposqrt(unittest.TestCase): 56 | 57 | def setUp(self): 58 | self.x = [2, 3, 4, 5, 6] 59 | self.ens = [-29.1322987785, -29.1337749163, -29.1340309055, 60 | -29.1341443009, -29.1341692835] 61 | 62 | def tearDown(self): 63 | del self.x 64 | del self.ens 65 | 66 | def test_exposqrt_2point(self): 67 | f = cbs.exposqrt(twopoint=True) 68 | eopt, ecov = curve_fit(f, self.x[-2:], self.ens[-2:]) 69 | self.assertAlmostEqual(-29.1341567932, eopt[0]) 70 | 71 | def test_exposqrt_3point(self): 72 | f = cbs.exposqrt(twopoint=False) 73 | eopt, ecov = curve_fit(f, self.x[-3:], self.ens[-3:]) 74 | self.assertAlmostEqual(-29.1341783198, eopt[0]) 75 | 76 | def test_exposqrt_4point(self): 77 | f = cbs.exposqrt(twopoint=False) 78 | eopt, ecov = curve_fit(f, self.x[-4:], self.ens[-4:]) 79 | self.assertAlmostEqual(-29.1342137839, eopt[0]) 80 | 81 | def test_exposqrt_5point(self): 82 | f = cbs.exposqrt(twopoint=False) 83 | eopt, ecov = curve_fit(f, self.x[-5:], self.ens[-5:]) 84 | self.assertAlmostEqual(-29.1341729017, eopt[0]) 85 | 86 | 87 | class TestExposum(unittest.TestCase): 88 | 89 | def setUp(self): 90 | self.x = [2, 3, 4, 5, 6] 91 | self.ens = [-29.1322987785, -29.1337749163, -29.1340309055, 92 | -29.1341443009, -29.1341692835] 93 | 94 | def tearDown(self): 95 | del self.x 96 | del self.ens 97 | 98 | def test_exposum_default(self): 99 | eopt, ecov = curve_fit(cbs.exposum(), self.x[-3:], self.ens[-3:]) 100 | self.assertAlmostEqual(-29.1341837985, eopt[0]) 101 | 102 | 103 | class TestUsteCI(unittest.TestCase): 104 | 105 | def setUp(self): 106 | # Be atom E_corr in CVXZ FCI 107 | self.x = [2, 3, 4, 5] 108 | self.ens = [-0.0794940093, -0.0894929639, -0.0927120458, -0.0935254940] 109 | 110 | def tearDown(self): 111 | del self.x 112 | del self.ens 113 | 114 | def test_uste_ci(self): 115 | f = cbs.uste('CI') 116 | eopt, ecov = curve_fit(f, self.x[-2:], self.ens[-2:]) 117 | self.assertAlmostEqual(-0.0943071693, eopt[0]) 118 | 119 | 120 | class TestUsteCC(unittest.TestCase): 121 | 122 | def setUp(self): 123 | # Be atom E_corr in CVXZ CCSD(T) 124 | self.x = [2, 3, 4, 5] 125 | self.ens = [-0.0794811580, -0.0894657703, -0.0926787765, -0.0934942304] 126 | 127 | def tearDown(self): 128 | del self.x 129 | del self.ens 130 | 131 | def test_uste_cc(self): 132 | f = cbs.uste('CC') 133 | eopt, ecov = curve_fit(f, self.x[-2:], self.ens[-2:]) 134 | self.assertAlmostEqual(-0.0942115430, eopt[0]) 135 | 136 | 137 | class TestExporapolate(unittest.TestCase): 138 | 139 | def setUp(self): 140 | # VO Be_2 VXZ corr energies at R_e 141 | self.x = [2, 3, 4, 5, 6] 142 | self.ens = [-0.1006245329, -0.1047828536, -0.1062511383, -0.1066997691, 143 | -0.1068704347] 144 | 145 | def tearDown(self): 146 | del self.x 147 | del self.ens 148 | 149 | def test_poly_2point_default(self): 150 | eopt = cbs.extrapolate(self.x[-2:], self.ens[-2:], 'poly') 151 | self.assertAlmostEqual(-0.1071048655, eopt[0]) 152 | 153 | def test_poly_3point(self): 154 | eopt = cbs.extrapolate(self.x[-3:], self.ens[-3:], 'poly', 155 | twopoint=False) 156 | self.assertAlmostEqual(-0.1070460458, eopt[0]) 157 | 158 | 159 | if __name__ == "__main__": 160 | unittest.main() 161 | -------------------------------------------------------------------------------- /chemtools/pescan/controller.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import numpy as np 4 | import os 5 | 6 | from itertools import product 7 | 8 | from sqlalchemy import create_engine 9 | from sqlalchemy.orm import sessionmaker 10 | from chemtools.pescan.model import Base, Atom, Dimer, Trimer, Tetramer 11 | 12 | 13 | def grid_product(dicts): 14 | ''' 15 | Given a dict whose item are lists return a generator over dict with 16 | all possible selections from the list (cartesian product) 17 | 18 | >>> options = {"number": [1,2,3], "color": ["orange","blue"] } 19 | >>> print list( my_product(options) ) 20 | [ {"number": 1, "color": "orange"}, 21 | {"number": 1, "color": "blue"}, 22 | {"number": 2, "color": "orange"}, 23 | {"number": 2, "color": "blue"}, 24 | {"number": 3, "color": "orange"}, 25 | {"number": 3, "color": "blue"} 26 | ] 27 | ''' 28 | return (dict(zip(dicts, x)) for x in product(*dicts.itervalues())) 29 | 30 | 31 | def expand_grids(grids=[], debug=False): 32 | 33 | '''Expand the grid definition and calculate all the grid points.''' 34 | 35 | res = list() 36 | for grid in grids: 37 | array = np.empty(0) 38 | for start, stop, num in grid: 39 | array = np.concatenate((array, np.linspace(start, stop, num)), axis=0) 40 | res.append(array) 41 | return res 42 | 43 | # controller methods 44 | 45 | 46 | def add_atom(session, name, basisset): 47 | 48 | atom = Atom(name=name, 49 | abspath=None, 50 | output_name=None, 51 | basisset=basisset, 52 | hf_energy=None, 53 | ci_energy=None, 54 | cc_energy=None, 55 | status=None) 56 | session.add(atom) 57 | session.commit() 58 | return True 59 | 60 | 61 | def add_trimer(session, name, basisset, ram, raa, gamma): 62 | ''' 63 | Add a Trimer to the database. 64 | ''' 65 | 66 | trimer = Trimer( 67 | name=name, 68 | abspath=None, 69 | output_name=None, 70 | basisset=basisset, 71 | hf_energy=None, 72 | ci_energy=None, 73 | cc_energy=None, 74 | status=None, 75 | r_atom_mol=ram, 76 | gamma=gamma, 77 | r_atom1_atom2=raa) 78 | session.add(trimer) 79 | session.commit() 80 | return True 81 | 82 | 83 | def add_tetramer(session, name, basisset, r_mol1_mol2, r_mol1, r_mol2, phi_1, 84 | phi_2, gamma): 85 | ''' 86 | Add a Tetramer to the database. 87 | ''' 88 | 89 | tetramer = Tetramer( 90 | name=name, 91 | basisset=basisset, 92 | r_mol1_mol2=r_mol1_mol2, 93 | r_mol1=r_mol1, 94 | r_mol2=r_mol2, 95 | gamma=gamma, 96 | phi_1=phi_1, 97 | phi_2=phi_2) 98 | session.add(tetramer) 99 | session.commit() 100 | return True 101 | 102 | 103 | def add_dimer(session, name, basisset, raa): 104 | ''' 105 | Loop over all jobs and return a list of dicts with job info 106 | 107 | Args: 108 | session: 109 | database session object (connection) 110 | name : str 111 | name of the system 112 | basissets : list 113 | list of strings with basis set names 114 | grids : numpy.array 115 | 1-D numpy array with the values of the internuclear distances 116 | 117 | ''' 118 | 119 | dimer = Dimer(name=name, 120 | abspath=None, 121 | output_name=None, 122 | basisset=basisset, 123 | hf_energy=None, 124 | ci_energy=None, 125 | cc_energy=None, 126 | status=None, 127 | r_atom1_atom2=raa) 128 | session.add(dimer) 129 | session.commit() 130 | return True 131 | 132 | 133 | def create_dirs(session, modelobj=None, workdir=os.getcwd()): 134 | ''' 135 | Create the directory tree associated with a given table. 136 | ''' 137 | 138 | # if workdir doesn't exist create it 139 | # raise exception when modelobj is None 140 | 141 | os.chdir(workdir) 142 | 143 | molecules = session.query(modelobj.name).distinct().all() 144 | for mol in molecules: 145 | os.mkdir(mol.name) 146 | os.chdir(mol.name) 147 | basis = session.query(modelobj.basisset).filter(modelobj.name == mol.name).distinct().all() 148 | for bas in basis: 149 | os.mkdir(bas.basisset) 150 | jobpath = os.path.join(os.getcwd(), bas.basisset) 151 | for entry in session.query(modelobj).filter(modelobj.name == mol.name).filter(modelobj.basisset == bas.basisset).all(): 152 | entry.abspath = jobpath 153 | session.add(entry) 154 | os.chdir("..") 155 | session.commit() 156 | 157 | # database connection methods 158 | 159 | def new_db(path): 160 | ''' 161 | Create a new database under path and return the session. 162 | ''' 163 | engine = create_engine("sqlite:///{path:s}".format(path=path), echo=False) 164 | Base.metadata.create_all(engine) 165 | db_session = sessionmaker(bind=engine) 166 | return db_session() 167 | 168 | def get_session(dbpath): 169 | ''' 170 | Connect to a database under the name stored in "path" and return the 171 | session. 172 | ''' 173 | 174 | if not os.path.exists(dbpath): 175 | raise OSError("database {0} does not exist".format(path)) 176 | 177 | engine = create_engine("sqlite:///{path:s}".format(path=dbpath), echo=False) 178 | db_session = sessionmaker(bind=engine) 179 | return db_session() 180 | -------------------------------------------------------------------------------- /chemtools/parsetools.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | ''' 26 | Module with convenience functions for parsing files 27 | ''' 28 | 29 | from __future__ import print_function 30 | 31 | import itertools 32 | from collections import defaultdict 33 | 34 | 35 | def contains(string, query): 36 | 'Check if `string` contains `query`' 37 | return string.find(query) > -1 38 | 39 | 40 | def locatelinenos(filename, tolocate): 41 | ''' 42 | Given a file and a list of strings return a dict with string as keys 43 | and line numbers in which they appear a values. 44 | 45 | Args: 46 | filename : str 47 | Name of the file 48 | tolocate : list of tuples 49 | List of tuples with strings to find (queries) as first elements and 50 | integer offset values as second 51 | 52 | Returns: 53 | out : dict 54 | Dictionary whose keys are indices corresponding to item in input list 55 | and values are lists of line numbers in which those string appear 56 | 57 | TODO: 58 | - add option to ignore the case of the strings to search 59 | ''' 60 | 61 | out = defaultdict(list) 62 | for lineno, line in enumerate(open(filename, 'r')): 63 | for idx, (query, offset) in enumerate(tolocate): 64 | if contains(line, query): 65 | out[idx].append(lineno + offset) 66 | return out 67 | 68 | 69 | def getlines(filename, tolocate): 70 | ''' 71 | Return the lines from the files based on `tolocate` 72 | 73 | Args: 74 | filename : str 75 | Name of the file 76 | tolocate : list of tuples 77 | List of tuples with strings to find (queries) as first elements and 78 | integer offset values as second 79 | 80 | Return: 81 | ''' 82 | 83 | located = locatelinenos(filename, tolocate) 84 | 85 | if len(tolocate) == len(located): 86 | for k, v in located.items(): 87 | if len(v) > 1: 88 | raise ValueError('multiple lines found for "{0}": {1}'.format( 89 | tolocate[k][0], ', '.join([str(x) for x in v]))) 90 | 91 | startlno = min(list(itertools.chain(*located.values()))) 92 | endlno = max(list(itertools.chain(*located.values()))) 93 | return getchunk(filename, startlno, endlno) 94 | else: 95 | # TODO: this needs to be corrected to be more informative 96 | raise ValueError('len(tolocate) != len(located): {0} != {1}'.format( 97 | len(tolocate), len(located))) 98 | 99 | 100 | def getchunk(filename, startlno, endlno): 101 | ''' 102 | Get a list of lines from a file between specified line numbers `startlno` 103 | and `endlno`. 104 | 105 | Args: 106 | filename : str 107 | Name of the file to process 108 | startlno : int 109 | Number of the first line to obtain 110 | endlno : int 111 | Number of the last line to obtain 112 | 113 | Returns: 114 | lines : list 115 | A list of lines from the file `filename` between line numbers\ 116 | `startlno` and `endlno` 117 | ''' 118 | 119 | fobj = open(filename, 'r') 120 | fileiter = iter(fobj) 121 | 122 | for _ in range(startlno): 123 | next(fileiter) 124 | 125 | return [next(fileiter) for _ in range(endlno - startlno)] 126 | 127 | 128 | def take(seq, num): 129 | ''' 130 | Iterate over a sequence `seq` `num` times and return the list of the 131 | elements iterated over. 132 | ''' 133 | return [next(seq) for _ in range(num)] 134 | 135 | 136 | def parsepairs(los, sep="="): 137 | ''' 138 | Parse a given list of strings "los" into a dictionary based on 139 | separation by "sep" character and return the dictionary. 140 | ''' 141 | 142 | out = [] 143 | for line in los: 144 | if sep in line: 145 | (name, value) = line.split(sep) 146 | out.append((name.strip(), float(value))) 147 | return dict(out) 148 | 149 | 150 | def sliceafter(seq, item, num): 151 | ''' 152 | Return "num" elements of a sequence "seq" present after the item "item". 153 | ''' 154 | 155 | it = iter(seq) 156 | for element in it: 157 | if item in element: 158 | return [next(it) for _ in range(num)] 159 | 160 | 161 | def slicebetween(string, start, end): 162 | ''' 163 | Return a slice of the `string` between phrases `start` and `end`. 164 | ''' 165 | 166 | istart = string.index(start) 167 | iend = string[istart:].index(end) 168 | return string[istart + len(start):istart + iend] 169 | -------------------------------------------------------------------------------- /chemtools/calculators/psi4.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | from __future__ import print_function 26 | from subprocess import Popen, call 27 | import os 28 | 29 | from .calculator import Calculator, InputTemplate, parse_objective 30 | 31 | 32 | class Psi4(Calculator): 33 | ''' 34 | Wrapper for the Psi4 program. 35 | ''' 36 | 37 | def __init__(self, name="Psi4", **kwargs): 38 | self.name = name 39 | self.inpext = '.dat' 40 | super(Psi4, self).__init__(**kwargs) 41 | 42 | self.psi4path = os.path.dirname(self.executable) 43 | 44 | def run(self, inpfile): 45 | ''' 46 | Run a single Psi4 job interactively - without submitting to the queue. 47 | ''' 48 | 49 | outfile = os.path.splitext(inpfile)[0] + ".out" 50 | 51 | command = [self.executable, inpfile] + self.runopts 52 | call(command) 53 | 54 | return outfile 55 | 56 | def run_multiple(self, inputs): 57 | ''' 58 | Run a single Psi4 job interactively - without submitting to the queue. 59 | ''' 60 | 61 | procs = [] 62 | outputs = [os.path.splitext(inp)[0] + ".out" for inp in inputs] 63 | for inpfile, outfile in zip(inputs, outputs): 64 | opts = [] 65 | opts.extend([self.executable, inpfile] + self.runopts) 66 | out = open(outfile, 'w') 67 | process = Popen(opts, stdout=out, stderr=out) 68 | out.close() 69 | procs.append(process) 70 | 71 | for proc in procs: 72 | proc.wait() 73 | 74 | return outputs 75 | 76 | def write_input(self, fname, template, mol=None, basis=None, core=None): 77 | ''' 78 | Write the Psi4 input to "fname" file based on the information from the 79 | keyword arguments. 80 | 81 | Args: 82 | mol : :py:class:`chemtools.molecule.Molecule` 83 | Molecule object instance 84 | basis : dict or :py:class:`BasisSet ` 85 | An instance of :py:class:`BasisSet ` class or a 86 | dictionary of :py:class:`BasisSet ` objects with 87 | element symbols as keys 88 | core : list of ints 89 | Psi4 core specification 90 | template : :py:class:`str` 91 | Template of the input file 92 | fname : :py:class:`str` 93 | Name of the input file to be used 94 | ''' 95 | 96 | temp = InputTemplate(template) 97 | 98 | if isinstance(basis, dict): 99 | bs_str = "".join(x.to_gaussian() for x in basis.values()) 100 | else: 101 | bs_str = basis.to_gaussian() 102 | 103 | if core is not None: 104 | core = "core,{0:s}\n".format(",".join([str(x) for x in core])) 105 | else: 106 | core = '' 107 | 108 | subs = { 109 | 'geometry' : mol.molpro_rep(), 110 | 'basisset' : bs_str + "\n", 111 | 'core' : core, 112 | } 113 | 114 | with open(fname, 'w') as inp: 115 | inp.write(temp.substitute(subs)) 116 | 117 | def parse(self, fname, objective, regularexp=None): 118 | ''' 119 | Parse a value from the output file ``fname`` based on the ``objective``. 120 | 121 | If the value of the ``objective`` is ``regexp`` then the ``regularexp`` will 122 | be used to parse the file. 123 | ''' 124 | 125 | regexps = { 126 | 'hf total energy' : r'@RHF Final Energy:\s+(\-?\d+\.\d+)', 127 | 'cisd total energy' : r'\s+\* CISD total energy:\s*(\-?\d+\.\d+)', 128 | 'accomplished' : r'\*\*\* PSI4 exiting successfully.', 129 | } 130 | 131 | if objective == 'regexp': 132 | toparse = regularexp 133 | else: 134 | toparse = regexps.get(objective, None) 135 | if toparse is None: 136 | raise ValueError("Specified objective: '{0:s}' not supported".format(objective)) 137 | 138 | return parse_objective(fname, toparse) 139 | 140 | def __repr__(self): 141 | return "\n".join(["\n"]) 148 | -------------------------------------------------------------------------------- /chemtools/submitmolpro.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | import argparse 26 | import os 27 | import socket 28 | import subprocess 29 | 30 | 31 | def main(): 32 | ''' 33 | Script for submitting molpro job to the queue. 34 | ''' 35 | 36 | parser = argparse.ArgumentParser() 37 | group = parser.add_mutually_exclusive_group() 38 | parser.add_argument("input", 39 | help='molpro input file to be executed') 40 | parser.add_argument("-d", 41 | "--dryrun", 42 | action="store_true", 43 | help="write the pbs script but don't submit to the queue, default-False") 44 | parser.add_argument("-e", 45 | "--extrafiles", 46 | nargs="+", 47 | default=[], 48 | help="additional files that need to be copied to the node/scratch") 49 | group.add_argument("-n", 50 | "--nodes", 51 | default="1", 52 | help="number of nodes, default=1") 53 | group.add_argument("-H", 54 | "--HOST", 55 | default="", 56 | help="destination hostname, default=''") 57 | parser.add_argument("-p", 58 | "--ppn", 59 | default="1", 60 | help="number of processes per node, default=1") 61 | parser.add_argument("-s", 62 | "--usescratch", 63 | action="store_true", 64 | help="use node scratch directory (/scratch/$USER)", 65 | default=False) 66 | parser.add_argument("-q", 67 | "--queue", 68 | default="default", 69 | help="destination queue, default=default") 70 | parser.add_argument("-t", 71 | "--walltime", 72 | default="120:00:00", 73 | help="walltime in the format HH:MM:SS,\ 74 | default=120:00:00") 75 | args = vars(parser.parse_args()) 76 | submit_pbs(args) 77 | 78 | 79 | def set_defaults(args): 80 | '''Set some useful default values and add them to args''' 81 | 82 | args['workdir'] = os.getcwd() 83 | args['home'] = os.getenv("HOME") 84 | if socket.gethostname() == "boron.chem.umk.pl": 85 | args['scratch'] = os.path.join('/scratch', os.getenv('USER')) 86 | args['molpro'] = '/share/apps/molprop_2012_1_Linux_x86_64_i8/bin/molpro' 87 | else: 88 | args['scratch'] = os.getenv("TMPDIR") 89 | args['molpro'] = 'molpro' 90 | args['local_scr'] = os.path.join(os.getenv('HOME'), 'scratch') 91 | args['jobname'] = os.path.splitext(args["input"])[0] 92 | args['outfile'] = args['jobname'] + ".o${PBS_JOBID}" 93 | args['errfile'] = args['jobname'] + ".e${PBS_JOBID}" 94 | args['script_name'] = "run." + args['jobname'] 95 | return args 96 | 97 | 98 | def submit_pbs(args): 99 | ''' 100 | Write the run script for PBS and submit it to the queue. 101 | ''' 102 | 103 | args = set_defaults(args) 104 | 105 | with open(args['script_name'], 'w') as script: 106 | script.write("#PBS -S /bin/bash\n") 107 | if args['HOST'] != "": 108 | script.write("#PBS -l nodes={0}:ppn={1}\n".format(args['HOST'], args['ppn'])) 109 | else: 110 | script.write("#PBS -l nodes={0}:ppn={1}\n".format(args['nodes'], args['ppn'])) 111 | if "mem" in args.keys(): 112 | script.write("#PBS -l mem={0}\n".format(args["mem"])) 113 | script.write("#PBS -l walltime={0}\n\n".format(args['walltime'])) 114 | #script.write('export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/share/apps/lib\n\n') 115 | script.write("#PBS -o {}\n".format(args["outfile"])) 116 | script.write("#PBS -e {}\n".format(args["errfile"])) 117 | script.write("#PBS -N {}\n".format(args["jobname"])) 118 | if args["queue"] != "default": 119 | script.write("#PBS -q {}\n".format(args["queue"])) 120 | script.write("cd $PBS_O_WORKDIR\n") 121 | if args['usescratch']: 122 | wrkdir = os.path.join(args['scratch'], args['jobname']) 123 | script.write("mkdir -p {}\n".format(wrkdir)) 124 | files = args['jobname'] 125 | if args['extrafiles']: 126 | files += ' ' + ' '.join(args['extrafiles']) 127 | script.write('cp -t {0} {1}\n'.format(wrkdir, files)) 128 | script.write('cd {0}\n'.format(wrkdir)) 129 | script.write("\n{0:\n"]) 124 | 125 | def write_input(self, fname=None, template=None, mol=None, basis=None, core=None): 126 | ''' 127 | Write the molpro input to "fname" file based on the information from the 128 | keyword arguments. 129 | 130 | Args: 131 | mol : :py:class:`chemtools.molecule.Molecule` 132 | Molecule object instance 133 | basis : dict or :py:class:`BasisSet ` 134 | An instance of :py:class:`BasisSet ` class or a 135 | dictionary of :py:class:`BasisSet ` objects with 136 | element symbols as keys 137 | core : list of ints 138 | Molpro core specification 139 | template : :py:class:`str` 140 | Template of the input file 141 | fname : :py:class:`str` 142 | Name of the input file to be used 143 | ''' 144 | 145 | temp = InputTemplate(template) 146 | 147 | if isinstance(basis, dict): 148 | bs_str = "".join(x.to_molpro() for x in basis.values()) 149 | else: 150 | bs_str = basis.to_molpro() 151 | 152 | if core is not None: 153 | core = "core,{0:s}\n".format(",".join([str(x) for x in core])) 154 | else: 155 | core = '' 156 | 157 | subs = { 158 | 'geometry' : mol.molpro_rep(), 159 | 'basis' : "basis={\n"+bs_str+"\n}\n", 160 | 'core' : core, 161 | } 162 | 163 | with open(fname, 'w') as inp: 164 | inp.write(temp.substitute(subs)) 165 | -------------------------------------------------------------------------------- /chemtools/calculators/calculator.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | ''' 26 | An abstract class that should be subclassed when addding a new code interface. 27 | 28 | All the methods should be implemented for the basisopt module to work with the 29 | new code. 30 | ''' 31 | 32 | import os 33 | import re 34 | 35 | from string import Template 36 | 37 | from abc import ABCMeta, abstractmethod 38 | 39 | 40 | class Calculator(): 41 | ''' 42 | Abstract class that should be subclassed when adding a new code interace. 43 | ''' 44 | __metaclass__ = ABCMeta 45 | 46 | def __init__(self, exevar=None, executable=None, runopts=None, 47 | scratch=None): 48 | 49 | self.exevar = exevar 50 | 51 | if executable is None and exevar is None: 52 | self.exe_found = False 53 | elif executable is None and os.getenv(self.exevar) is not None: 54 | self.executable = os.getenv(self.exevar) 55 | self.exe_found = True 56 | elif executable is not None and exevar is None: 57 | self.executable = executable 58 | self.exe_found = True 59 | elif executable is not None and exevar is not None: 60 | exefromvar = os.getenv(self.exevar) 61 | if os.path.abspath(exefromvar) == os.path.abspath(executable): 62 | self.executable = exefromvar 63 | self.exe_found = True 64 | else: 65 | raise ValueError('conflicting and options specified: '\ 66 | '{0:s} != {1:s}'.format(executable, exefromvar)) 67 | 68 | self.runopts = runopts 69 | self.scratch = scratch 70 | 71 | @property 72 | def executable(self): 73 | 'Set the executable' 74 | return self._executable 75 | 76 | @executable.setter 77 | def executable(self, value): 78 | if os.path.exists(value): 79 | if os.path.isdir(value): 80 | raise OSError('{0} is a directory, not executable'.format(value)) 81 | elif os.path.isfile(value): 82 | if os.access(value, os.X_OK): 83 | self._executable = value 84 | else: 85 | raise OSError('file: {0} is not executable'.format(value)) 86 | else: 87 | raise OSError('unknown type of the executable: {0}'.format(value)) 88 | else: 89 | raise ValueError("executable: '{0}' does not exists".format(value)) 90 | 91 | @property 92 | def scratch(self): 93 | 'Return scratch' 94 | return self._scratch 95 | 96 | @scratch.setter 97 | def scratch(self, path): 98 | 99 | if path is None: 100 | self._scratch = os.path.join(os.getenv('HOME'), 'scratch') 101 | elif os.path.exists(path): 102 | self._scratch = path 103 | else: 104 | raise ValueError("Scratch directory doesn't exist: {}".format(path)) 105 | 106 | @abstractmethod 107 | def parse(self, fname, objective, regexp=None): 108 | ''' 109 | Parse the value of the ``objective`` from the file ``fname`` 110 | ''' 111 | pass 112 | 113 | @abstractmethod 114 | def run(self, *args): 115 | ''' 116 | run a single job 117 | ''' 118 | 119 | pass 120 | 121 | @abstractmethod 122 | def run_multiple(self, *args): 123 | ''' 124 | Run multiple jobs 125 | ''' 126 | pass 127 | 128 | def accomplished(self, fname): 129 | ''' 130 | Return True if the job completed without errors 131 | ''' 132 | 133 | return self.parse(fname, 'accomplished') is True 134 | 135 | @abstractmethod 136 | def write_input(self): 137 | ''' 138 | write the input file in the format of the code used 139 | ''' 140 | pass 141 | 142 | 143 | def parse_objective(fname, regexp, reflags=re.I): 144 | ''' 145 | Wrapper for the parse methods 146 | 147 | Args: 148 | fname : :py:class:`str` 149 | Name of the file to be parsed 150 | regexp : :py:class:`str` 151 | Regular expression as raw string 152 | reflags : 153 | Flags for the regular expression compilation 154 | ''' 155 | 156 | if not os.path.exists(fname): 157 | raise ValueError("Output file: {0:s} doesn't exist in {1:s}".format(fname, os.getcwd())) 158 | 159 | rec = re.compile(regexp, flags=reflags) 160 | with open(fname, 'r') as fobj: 161 | for line in fobj: 162 | match = rec.search(line) 163 | if match: 164 | # check if a group was captured or not 165 | if match.lastindex is not None and match.lastindex > 0: 166 | return float(match.group(1)) 167 | else: 168 | return True 169 | else: 170 | return None 171 | 172 | 173 | class InputTemplate(Template): 174 | 175 | 'Modified string.Template class to be used for input rendering' 176 | 177 | delimiter = '%' 178 | idpattern = r'[a-z][_a-z0-9]*' 179 | 180 | def get_keys(self): 181 | ''' 182 | Parse the string and return a dict with possible keys to substitute. 183 | For most use case only the `named` fields are interesting. 184 | ''' 185 | 186 | keys = {} 187 | match = self.pattern.findall(self.template) 188 | for key, val in self.pattern.groupindex.items(): 189 | keys[key] = [x[val - 1] for x in match if x[val - 1] != ''] 190 | return keys 191 | -------------------------------------------------------------------------------- /tests/test_gamessus/test_GamessInput.py: -------------------------------------------------------------------------------- 1 | import os 2 | import unittest 3 | 4 | from chemtools.calculators.gamessus import GamessInput 5 | 6 | class TestGIPonHeH2(unittest.TestCase): 7 | 8 | def setUp(self): 9 | inpfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data/heh2/he-h2_avdz_ormas.inp') 10 | self.gip = GamessInput(fname=inpfile) 11 | self.gip.parse() 12 | 13 | def test_inpdict(self): 14 | self.assertIsInstance(self.gip.parsed, dict) 15 | 16 | def test_contrl(self): 17 | d ={"scftyp" : "rhf", 18 | "cityp" : "ormas", 19 | "runtyp" : "energy", 20 | "maxit" : "30", 21 | "mult" : "1", 22 | "icut" : "30", 23 | "itol" : "30", 24 | "ispher" : "1", 25 | "units" : "bohr"} 26 | self.assertDictEqual(d, self.gip.parsed["$contrl"]) 27 | 28 | def test_trans(self): 29 | d = {"cuttrf" : "1.0d-10"} 30 | self.assertDictEqual(d, self.gip.parsed["$trans"]) 31 | 32 | def test_system(self): 33 | d = {"timlim" : "525600", 34 | "mwords" : "100"} 35 | self.assertDictEqual(d, self.gip.parsed["$system"]) 36 | 37 | def test_title(self): 38 | self.assertEqual(self.gip.parsed["$data"]["title"], "He-H2 FCI") 39 | 40 | def test_group(self): 41 | self.assertEqual(self.gip.parsed["$data"]["group"], "cnv 2") 42 | 43 | def test_atoms(self): 44 | self.assertEqual(len(self.gip.parsed["$data"]["atoms"]), 2) 45 | 46 | def test_atom1_xyz(self): 47 | t = tuple([0.0, 0.0, -3.0]) 48 | self.assertTupleEqual(t, self.gip.parsed["$data"]["atoms"][0]["xyz"]) 49 | 50 | def test_atom1_atomic(self): 51 | self.assertEqual(self.gip.parsed["$data"]["atoms"][0]["atomic"], 2.0) 52 | 53 | def test_atom1_label(self): 54 | self.assertEqual(self.gip.parsed["$data"]["atoms"][0]["label"], "He") 55 | 56 | def test_atom2_xyz(self): 57 | t = tuple([0.0, 0.724368, 3.0]) 58 | self.assertTupleEqual(t, self.gip.parsed["$data"]["atoms"][1]["xyz"]) 59 | 60 | def test_atom2_atomic(self): 61 | self.assertEqual(self.gip.parsed["$data"]["atoms"][1]["atomic"], 1.0) 62 | 63 | def test_atom2_label(self): 64 | self.assertEqual(self.gip.parsed["$data"]["atoms"][1]["label"], "H") 65 | 66 | class TestGIPonNe(unittest.TestCase): 67 | ne_no_inp = ''' $CONTRL 68 | scftyp=none 69 | RUNTYP=ENERGY 70 | CITYP=GUGA 71 | MAXIT=200 72 | MULT=1 73 | ISPHER=1 74 | ICUT=20 75 | ITOL=20 76 | QMTTOL=1.E-8 77 | ICHARG=0 78 | $END 79 | $SYSTEM TIMLIM=14400 MWORDS=100 MEMDDI=0 $END 80 | $SCF 81 | DIRSCF=.F. FDIFF=.F. VVOS=.F. 82 | $END 83 | $CIDRT 84 | iexcit=2 85 | nfzc=1 86 | ndoc=4 87 | nval=9 88 | group=d2h 89 | STSYM=AG 90 | $END 91 | $GUGDIA 92 | CVGTOL=1E-10 93 | $END 94 | $BASIS GBASIS=CCD $END 95 | $DATA 96 | Title 97 | DNH 2 98 | 99 | NE 10.0 0.00000000 0.00000000 0.0000000 100 | $END 101 | $GUESS guess=moread norb=14 $END 102 | 103 | $VEC 104 | 1 1 1.00040943E+00 2.94355142E-07-2.09957395E-03 0.00000000E+00 0.00000000E+00 105 | 1 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 106 | 1 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 107 | 2 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 6.96472997E-01 0.00000000E+00 108 | 2 2 0.00000000E+00 4.55660763E-01 0.00000000E+00 0.00000000E+00 0.00000000E+00 109 | 2 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 110 | 3 1-5.82488255E-01-1.26490410E+00 1.62236917E+00 0.00000000E+00 0.00000000E+00 111 | 3 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 112 | 3 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 113 | 4 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 114 | 4 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 115 | 4 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 1.00000000E+00 0.00000000E+00 116 | 5 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 5.80423950E-01 117 | 5 2 0.00000000E+00 0.00000000E+00 5.80423950E-01 0.00000000E+00 0.00000000E+00 118 | 5 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 119 | 6 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-9.84522233E-01 120 | 6 2-0.00000000E+00-0.00000000E+00 9.84522233E-01-0.00000000E+00-0.00000000E+00 121 | 6 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 122 | 7 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 123 | 7 2 5.80423950E-01 0.00000000E+00 0.00000000E+00 5.80423950E-01 0.00000000E+00 124 | 7 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 125 | 8 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 126 | 8 2-9.84522233E-01-0.00000000E+00-0.00000000E+00 9.84522233E-01-0.00000000E+00 127 | 8 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 128 | 9 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 129 | 9 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 130 | 9 3 0.00000000E+00 0.00000000E+00 1.00000000E+00 0.00000000E+00 0.00000000E+00 131 | 10 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 132 | 10 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 133 | 10 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 1.00000000E+00 134 | 11 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 135 | 11 2-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 8.66025404E-01 136 | 11 3-8.66025404E-01-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 137 | 12 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 138 | 12 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-5.00000000E-01 139 | 12 3-5.00000000E-01 1.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 140 | 13 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-9.06146430E-01-0.00000000E+00 141 | 13 2-0.00000000E+00 1.04811701E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 142 | 13 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 143 | 14 1 2.16942447E-01 1.02369108E+00-1.09192955E-03 0.00000000E+00 0.00000000E+00 144 | 14 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 145 | 14 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 146 | $END''' 147 | 148 | def setUp(self): 149 | self.gip = GamessInput() 150 | self.gip.parse_from_string(TestGIPonNe.ne_no_inp) 151 | 152 | def test_inpdict(self): 153 | self.assertIsInstance(self.gip.parsed, dict) 154 | 155 | def test_vec(self): 156 | self.assertIsInstance(self.gip.parsed["$vec"], str) 157 | 158 | if __name__ == "__main__": 159 | unittest.main() 160 | -------------------------------------------------------------------------------- /chemtools/calculators/dalton.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | import os 26 | from collections import Counter 27 | from subprocess import Popen, call 28 | 29 | from .calculator import Calculator, InputTemplate, parse_objective 30 | 31 | from ..basisset import get_l 32 | 33 | 34 | class Dalton(Calculator): 35 | 36 | 'Wrapper for running Dalton program' 37 | 38 | def __init__(self, name='Dalton', **kwargs): 39 | 40 | self.name = name 41 | super(Dalton, self).__init__(**kwargs) 42 | 43 | self.daltonpath = os.path.dirname(self.executable) 44 | 45 | def parse(self, fname, objective, regularexp=None): 46 | ''' 47 | Parse a value from the output file ``fname`` based on the 48 | ``objective``. 49 | 50 | If the value of the ``objective`` is ``regexp`` then the 51 | ``regularexp`` will be used to parse the file. 52 | ''' 53 | 54 | regexps = { 55 | 'hf total energy': r'^@\s+Final HF energy:\s*(\-?\d+\.\d+)', 56 | 'cisd total energy': r'\d+\s*\d+\s*(\-?\d+\.\d+).*converged', 57 | 'accomplished': r'End of Wave Function Section', 58 | } 59 | 60 | if objective == 'regexp': 61 | if regularexp is None: 62 | raise ValueError(" needs to be specified for objective='regexp'") 63 | toparse = regularexp 64 | else: 65 | toparse = regexps.get(objective, None) 66 | if toparse is None: 67 | raise ValueError("Specified objective: '{0:s}' not supported".format(objective)) 68 | 69 | return parse_objective(fname, toparse) 70 | 71 | def run(self, fname): 72 | ''' 73 | Run a single job 74 | 75 | Args: 76 | fname : dict 77 | A dictionary with keys ``mol`` and ``dal`` and their 78 | respective file name strings as values 79 | 80 | Returns: 81 | out : str 82 | Name of the dalton output file 83 | ''' 84 | 85 | dalbase = os.path.splitext(fname['dal'])[0] 86 | molbase = os.path.splitext(fname['mol'])[0] 87 | 88 | command = [self.executable] + self.runopts + [dalbase, molbase] 89 | call(command) 90 | 91 | return dalbase + '_' + molbase + '.out' 92 | 93 | def run_multiple(self, fnames): 94 | ''' 95 | Spawn two single jobs as paralell processes 96 | ''' 97 | 98 | procs = [] 99 | outputs = [] 100 | for fname in fnames: 101 | 102 | dalbase = os.path.splitext(fname['dal'])[0] 103 | molbase = os.path.splitext(fname['mol'])[0] 104 | outputs.append(dalbase + '_' + molbase + '.out') 105 | 106 | command = [self.executable] + self.runopts + [dalbase, molbase] 107 | process = Popen(command) 108 | procs.append(process) 109 | 110 | for proc in procs: 111 | proc.wait() 112 | 113 | return outputs 114 | 115 | def write_input(self, fname, template, basis, mol, core): 116 | ''' 117 | Write dalton input files: ``fname.dal`` and ``system.mol`` 118 | 119 | Args: 120 | fname : str 121 | Name of the input file ``.dal`` 122 | template : dict 123 | Dictionary with templates for the ``dal`` and ``mol`` 124 | with those strings as keys and actual templates as 125 | values 126 | basis : dict 127 | An instance of 128 | :py:class:`BasisSet ` 129 | class or a dictionary of 130 | :py:class:`BasisSet ` 131 | objects with element symbols as keys 132 | mol : :py:class:`chemtools.molecule.Molecule` 133 | Molecule object with the system geometry 134 | core : str 135 | Core definition 136 | ''' 137 | 138 | # Dalton uses atomic units for xyz coordinats by default 139 | 140 | daltemplate = template['dal'] 141 | moltemplate = template['mol'] 142 | 143 | # loop over different elements (not atoms) 144 | atomtypes = Counter([a.symbol for a in mol.atoms]) 145 | out = '' 146 | for symbol, count in atomtypes.items(): 147 | atoms = [a for a in mol.atoms if a.symbol == symbol] 148 | atombasis = basis[symbol] 149 | atombasis.sort() 150 | # get max angular momentum + 1 and construct block string 151 | maxb = max([get_l(s) for s in atombasis.functions.keys()]) + 1 152 | block = str(maxb) + ' 1' * maxb 153 | out += 'Atoms={0:d} Charge={1:.1f} Block={2:s}\n'.format(count, 154 | float(atoms[0].atomic_number), 155 | block) 156 | for i, atom in enumerate(atoms, start=1): 157 | out += '{0:4s} {1:15.8f} {2:15.8f} {3:15.8f}\n'.format(atom.symbol+str(i), 158 | atom.xyz[0], atom.xyz[1], atom.xyz[2]) 159 | 160 | out += atombasis.to_dalton() 161 | 162 | molsubs = {'basis' : out} 163 | moltemp = InputTemplate(moltemplate) 164 | dalsubs = {'core' : core} 165 | daltemp = InputTemplate(daltemplate) 166 | 167 | with open(fname['mol'], 'w') as fmol: 168 | fmol.write(moltemp.substitute(molsubs)) 169 | 170 | with open(fname['dal'], 'w') as fdal: 171 | fdal.write(daltemp.substitute(dalsubs)) 172 | 173 | def __repr__(self): 174 | return "\n".join(["\n"]) 181 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/chemtools.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/chemtools.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/chemtools" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/chemtools" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /chemtools/molecule.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | ''' 26 | Module for handling atoms and molecules. 27 | ''' 28 | 29 | from math import sqrt 30 | import numpy as np 31 | from mendeleev import element 32 | 33 | 34 | class Atom(object): 35 | 36 | '''Basic atom class representing an atom.''' 37 | 38 | def __init__(self, identifier, xyz=(0.0, 0.0, 0.0), dummy=False, id=None): 39 | 40 | self.xyz = np.asarray(xyz) 41 | self.is_dummy = dummy 42 | self._set_attributes(identifier) 43 | 44 | @property 45 | def xyz(self): 46 | return self._xyz 47 | 48 | @xyz.setter 49 | def xyz(self, values): 50 | 51 | if len(values) != 3: 52 | raise ValueError("Expecting 3 coordinates (x, y, z), got: {0:d}".format(len(values))) 53 | else: 54 | self._xyz = np.asarray(values) 55 | 56 | def _set_attributes(self, identifier): 57 | ''' 58 | Set the attributes of an atom based on the unique "indentifier" provided. 59 | The attributes are read from the elements.json file. 60 | ''' 61 | 62 | attrs = ["name", "symbol", "atomic_number", "mass"] 63 | atom = element(identifier) 64 | 65 | for attr in attrs: 66 | setattr(self, attr, getattr(atom, attr)) 67 | 68 | if self.is_dummy: 69 | self.set_atomic_number(0.0) 70 | 71 | def set_atomic_number(self, value): 72 | self.atomic_number = value 73 | 74 | def move(self, x=0.0, y=0.0, z=0.0): 75 | 76 | '''Move atom to a set of new coordinates given in xyz''' 77 | 78 | self.xyz = np.asarray([x, y, z], dtype=self._dtxyz) 79 | 80 | def gamess_rep(self): 81 | 82 | out = "{0:<10s} {1:5.1f}\t{2:15.5f}{3:15.5f}{4:15.5f}\n".format( 83 | self.symbol, float(self.atomic_number), self.xyz[0], self.xyz[1], self.xyz[2]) 84 | return out 85 | 86 | def __repr__(self): 87 | out = "{0:<10s} {1:5.1f}\t{2:15.5f}{3:15.5f}{4:15.5f}".format( 88 | self.symbol, float(self.atomic_number), self.xyz[0], self.xyz[1], self.xyz[2]) 89 | return out 90 | 91 | def __str__(self): 92 | out = "{0:<10s} {1:14.2f}\t{2:15.5f}{3:15.5f}{4:15.5f}\n".format( 93 | self.symbol, float(self.atomic_number), self.xyz[0], self.xyz[1], self.xyz[2]) 94 | return out 95 | 96 | 97 | class Molecule(object): 98 | 99 | '''Molecule class handling all the operations on single molecules''' 100 | 101 | def __init__(self, name="", atoms=None, unique=None, sym="", charge=0, multiplicity=1): 102 | self.name = name 103 | self.charge = charge 104 | self.multiplicity = multiplicity 105 | self.atoms = atoms 106 | if sym == "": 107 | self.symmetry = "c1" 108 | else: 109 | self.symmetry = sym 110 | self.electrons = self.nele() 111 | if unique is not None: 112 | self.unique_labels = unique 113 | else: 114 | self.unique_labels = range(len(atoms)) 115 | 116 | @property 117 | def atoms(self): 118 | return self._atoms 119 | 120 | @atoms.setter 121 | def atoms(self, values): 122 | self._atoms = [] 123 | if hasattr(values, "__iter__"): 124 | for v in values: 125 | if len(v) == 1: 126 | self._atoms.append(Atom(identifier=v[0])) 127 | elif len(v) == 2: 128 | if isinstance(v[1], bool): 129 | self._atoms.append(Atom(identifier=v[0], dummy=v[1])) 130 | elif isinstance(v[1], (list, tuple)): 131 | self._atoms.append(Atom(identifier=v[0], xyz=v[1])) 132 | else: 133 | raise ValueError("Second argument should be or , not {}".format(type(v[1]))) 134 | elif len(v) == 3: 135 | self._atoms.append(Atom(identifier=v[0], xyz=v[1], dummy=v[2])) 136 | else: 137 | raise ValueError("wrong number of Atom arguments: {}, expecting: 1, 2, 3.".format(len(v))) 138 | else: 139 | raise TypeError("{0:s} object is not iterable".format(type(values))) 140 | 141 | def unique(self): 142 | '''Get a list of unique atom specified by unique keyword''' 143 | return [self.atoms[i] for i in self.unique_labels] 144 | 145 | def nele(self): 146 | 147 | '''Get the total number of electrons in a molecule.''' 148 | 149 | nelectrons = 0 150 | for atom in self.atoms: 151 | if atom.atomic_number > 0: 152 | nelectrons += atom.atomic_number 153 | return nelectrons - self.charge 154 | 155 | 156 | def get_distance(self, atom1, atom2): 157 | 158 | '''Calcualte the distance between two atoms.''' 159 | 160 | dist = 0.0 161 | for i in range(3): 162 | dist += (self.atoms[atom1].xyz[i]-self.atoms[atom2].xyz[i])**2 163 | return sqrt(dist) 164 | 165 | def gamess_rep(self): 166 | 167 | out = "" 168 | for atom in self.atoms: 169 | out = out + "{0:<10s} {1:5.1f}\t{2:15.5f}{3:15.5f}{4:15.5f}\n".format( 170 | atom.symbol, float(atom.atomic_number), atom.xyz[0], atom.xyz[1], atom.xyz[2]) 171 | return out 172 | 173 | def molpro_rep(self): 174 | 175 | out = "geomtyp=xyz\ngeometry={{\n{0:4d}\n{1:<80s}\n".format(len(self.atoms), self.name) 176 | for atom in self.atoms: 177 | out = out + "{0:<10s}, {1:15.5f}, {2:15.5f}, {3:15.5f}\n".format( 178 | atom.symbol, atom.xyz[0], atom.xyz[1], atom.xyz[2]) 179 | out = out + "}\n" 180 | return out 181 | 182 | def __repr__(self): 183 | 184 | out = "` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\chemtools.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\chemtools.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /doc/source/notebooks/Molpro_tutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Molpro tutorial\n", 8 | "\n", 9 | "The `molpro` module contains the `Molpro` convenience class, which is python wrapper for running the [Molpro] program with methods for writing input files, running the calculations and parsing the output files. \n", 10 | "\n", 11 | "[Molpro]: https://www.molpro.net/" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 3, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "from chemtools.calculators.molpro import Molpro" 21 | ] 22 | }, 23 | { 24 | "cell_type": "markdown", 25 | "metadata": {}, 26 | "source": [ 27 | "## Molpro wrapper\n", 28 | "\n", 29 | "`Molpro` object can be created by either providing the path to the molpro executable with `executable` keyword argument or name of the environmental variable holding the path through `exevar`." 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 5, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "molpro = Molpro(exevar=\"MOLPRO_EXE\",\n", 39 | " runopts=[\"-s\", \"-n\", \"1\"],\n", 40 | " scratch=\"/home/lmentel/scratch\")" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "Now we can write some sample molpro input and run in from python using the `Molpro` object created earlier." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 6, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "inpstr = '''***,H2O finite field calculations\n", 57 | "r=1.85,theta=104 !set geometry parameters\n", 58 | "geometry={O; !z-matrix input\n", 59 | "H1,O,r;\n", 60 | "H2,O,r,H1,theta}\n", 61 | "\n", 62 | "basis=avtz !define default basis\n", 63 | "\n", 64 | "hf\n", 65 | "ccsd(t)\n", 66 | "'''\n", 67 | "\n", 68 | "with open('h2o.inp', 'w') as finp:\n", 69 | " finp.write(inpstr)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "`run` method runs the job and returns the ouput file name" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 10, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "output = molpro.run('h2o.inp')" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 11, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "'h2o.out'" 97 | ] 98 | }, 99 | "execution_count": 11, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "output" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "## Parsing the results\n", 113 | "\n", 114 | "To check if the calculation finished without errors you can use `accomplished` method" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 13, 120 | "metadata": {}, 121 | "outputs": [ 122 | { 123 | "data": { 124 | "text/plain": [ 125 | "True" 126 | ] 127 | }, 128 | "execution_count": 13, 129 | "metadata": {}, 130 | "output_type": "execute_result" 131 | } 132 | ], 133 | "source": [ 134 | "molpro.accomplished(output)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 15, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "data": { 144 | "text/plain": [ 145 | "-76.058288041466" 146 | ] 147 | }, 148 | "execution_count": 15, 149 | "metadata": {}, 150 | "output_type": "execute_result" 151 | } 152 | ], 153 | "source": [ 154 | "molpro.parse(output, 'hf total energy')" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 16, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "molpro.parse(output, 'mp2 total energy')" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 18, 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "data": { 173 | "text/plain": [ 174 | "-76.341780640047" 175 | ] 176 | }, 177 | "execution_count": 18, 178 | "metadata": {}, 179 | "output_type": "execute_result" 180 | } 181 | ], 182 | "source": [ 183 | "molpro.parse(output, 'ccsd(t) total energy')" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 17, 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "data": { 193 | "text/plain": [ 194 | "8.99162654" 195 | ] 196 | }, 197 | "execution_count": 17, 198 | "metadata": {}, 199 | "output_type": "execute_result" 200 | } 201 | ], 202 | "source": [ 203 | "molpro.parse(output, 'regexp', regularexp=r'NUCLEAR REPULSION ENERGY\\s*(-?\\d+\\.\\d+)')" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 21, 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "data": { 213 | "application/json": { 214 | "Software versions": [ 215 | { 216 | "module": "Python", 217 | "version": "3.6.3 64bit [GCC 7.2.0]" 218 | }, 219 | { 220 | "module": "IPython", 221 | "version": "6.2.1" 222 | }, 223 | { 224 | "module": "OS", 225 | "version": "Linux 4.9.0 4 amd64 x86_64 with debian 9.1" 226 | }, 227 | { 228 | "module": "chemtools", 229 | "version": "0.8.4" 230 | } 231 | ] 232 | }, 233 | "text/html": [ 234 | "
SoftwareVersion
Python3.6.3 64bit [GCC 7.2.0]
IPython6.2.1
OSLinux 4.9.0 4 amd64 x86_64 with debian 9.1
chemtools0.8.4
Mon Nov 27 16:49:17 2017 CET
" 235 | ], 236 | "text/latex": [ 237 | "\\begin{tabular}{|l|l|}\\hline\n", 238 | "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", 239 | "Python & 3.6.3 64bit [GCC 7.2.0] \\\\ \\hline\n", 240 | "IPython & 6.2.1 \\\\ \\hline\n", 241 | "OS & Linux 4.9.0 4 amd64 x86\\_64 with debian 9.1 \\\\ \\hline\n", 242 | "chemtools & 0.8.4 \\\\ \\hline\n", 243 | "\\hline \\multicolumn{2}{|l|}{Mon Nov 27 16:49:17 2017 CET} \\\\ \\hline\n", 244 | "\\end{tabular}\n" 245 | ], 246 | "text/plain": [ 247 | "Software versions\n", 248 | "Python 3.6.3 64bit [GCC 7.2.0]\n", 249 | "IPython 6.2.1\n", 250 | "OS Linux 4.9.0 4 amd64 x86_64 with debian 9.1\n", 251 | "chemtools 0.8.4\n", 252 | "Mon Nov 27 16:49:17 2017 CET" 253 | ] 254 | }, 255 | "execution_count": 21, 256 | "metadata": {}, 257 | "output_type": "execute_result" 258 | } 259 | ], 260 | "source": [ 261 | "%version_information chemtools" 262 | ] 263 | } 264 | ], 265 | "metadata": { 266 | "kernelspec": { 267 | "display_name": "Python 3", 268 | "language": "python", 269 | "name": "python3" 270 | }, 271 | "language_info": { 272 | "codemirror_mode": { 273 | "name": "ipython", 274 | "version": 3 275 | }, 276 | "file_extension": ".py", 277 | "mimetype": "text/x-python", 278 | "name": "python", 279 | "nbconvert_exporter": "python", 280 | "pygments_lexer": "ipython3", 281 | "version": "3.6.3" 282 | } 283 | }, 284 | "nbformat": 4, 285 | "nbformat_minor": 1 286 | } 287 | -------------------------------------------------------------------------------- /tests/test_gamessus/data/ne/ne_dz_guga.dat: -------------------------------------------------------------------------------- 1 | $DATA 2 | Title 3 | DNH 2 4 | 5 | NE 10.0 0.0000000000 0.0000000000 0.0000000000 6 | CCD 0 7 | 8 | $END 9 | --- CLOSED SHELL ORBITALS --- GENERATED AT Thu Jul 31 01:23:18 2014 10 | Title 11 | E(RHF)= -128.4887755517, E(NUC)= 0.0000000000, 7 ITERS 12 | $VEC 13 | 1 1 1.00040943E+00 2.94355142E-07-2.09957395E-03-0.00000000E+00-0.00000000E+00 14 | 1 2-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 15 | 1 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 16 | 2 1 2.30043551E-07 5.17840219E-01 5.65215533E-01 0.00000000E+00 0.00000000E+00 17 | 2 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 18 | 2 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 19 | 3 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 20 | 3 2 6.96472997E-01 0.00000000E+00 0.00000000E+00 4.55660763E-01 0.00000000E+00 21 | 3 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 22 | 4 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 6.96472997E-01 0.00000000E+00 23 | 4 2 0.00000000E+00 4.55660763E-01 0.00000000E+00 0.00000000E+00 0.00000000E+00 24 | 4 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 25 | 5 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 6.96472997E-01 26 | 5 2 0.00000000E+00 0.00000000E+00 4.55660763E-01 0.00000000E+00 0.00000000E+00 27 | 5 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 28 | 6 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-9.06146430E-01-0.00000000E+00 29 | 6 2-0.00000000E+00 1.04811701E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 30 | 6 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 31 | 7 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-9.06146430E-01 32 | 7 2-0.00000000E+00-0.00000000E+00 1.04811701E+00-0.00000000E+00-0.00000000E+00 33 | 7 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 34 | 8 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 35 | 8 2-9.06146430E-01-0.00000000E+00-0.00000000E+00 1.04811701E+00-0.00000000E+00 36 | 8 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 37 | 9 1 6.21575894E-01 1.54264945E+00-1.52072822E+00 0.00000000E+00 0.00000000E+00 38 | 9 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 39 | 9 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 40 | 10 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 41 | 10 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 42 | 10 3 0.00000000E+00 0.00000000E+00 1.00000000E+00 0.00000000E+00 0.00000000E+00 43 | 11 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 44 | 11 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 45 | 11 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 1.00000000E+00 46 | 12 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 47 | 12 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-5.00000000E-01 48 | 12 3-5.00000000E-01 1.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 49 | 13 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 50 | 13 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 51 | 13 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 1.00000000E+00 0.00000000E+00 52 | 14 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 53 | 14 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 8.66025404E-01 54 | 14 3-8.66025404E-01 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 55 | $END 56 | POPULATION ANALYSIS 57 | NE 10.00000 -0.00000 10.00000 0.00000 58 | MOMENTS AT POINT 1 X,Y,Z= 0.000000 0.000000 0.000000 59 | DIPOLE 0.000000 0.000000 0.000000 60 | GUGA-CI NO-S FOR STATE 1 GENERATED Thu Jul 31 01:23:19 2014 61 | $OCC 62 | 1.9999536821 1.9928546205 1.9851160959 1.9851160955 1.9851160954 63 | 0.0110484597 0.0110484592 0.0110484588 0.0065683192 0.0024259428 64 | 0.0024259428 0.0024259428 0.0024259426 0.0024259426 65 | $END 66 | $VEC 67 | 1 1 1.00036352E+00-7.31455583E-03-1.03817167E-02-0.00000000E+00-0.00000000E+00 68 | 1 2-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 2.41408432E-12 69 | 1 3-2.72500653E-11 2.48359809E-11-0.00000000E+00-0.00000000E+00-0.00000000E+00 70 | 2 1 1.37091381E-02 5.16048685E-01 5.66839109E-01 0.00000000E+00 0.00000000E+00 71 | 2 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-2.60857671E-10 72 | 2 3-8.65648293E-11 3.47422501E-10 0.00000000E+00 0.00000000E+00 0.00000000E+00 73 | 3 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 6.95492205E-01 0.00000000E+00 74 | 3 2 0.00000000E+00 4.56794483E-01 0.00000000E+00 0.00000000E+00 0.00000000E+00 75 | 3 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 76 | 4 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 77 | 4 2 6.95492199E-01 0.00000000E+00 0.00000000E+00 4.56794489E-01 0.00000000E+00 78 | 4 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 79 | 5 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 6.95492194E-01 80 | 5 2 0.00000000E+00 0.00000000E+00 4.56794496E-01 0.00000000E+00 0.00000000E+00 81 | 5 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 82 | 6 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-9.06899441E-01 83 | 6 2-0.00000000E+00-0.00000000E+00 1.04762339E+00-0.00000000E+00-0.00000000E+00 84 | 6 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 85 | 7 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 86 | 7 2-9.06899437E-01-0.00000000E+00-0.00000000E+00 1.04762340E+00-0.00000000E+00 87 | 7 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 88 | 8 1-0.00000000E+00-0.00000000E+00-0.00000000E+00-9.06899433E-01-0.00000000E+00 89 | 8 2-0.00000000E+00 1.04762340E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 90 | 8 3-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00 91 | 9 1 6.21498610E-01 1.54323234E+00-1.52008979E+00 0.00000000E+00 0.00000000E+00 92 | 9 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-3.90142005E-09 93 | 9 3-2.96908785E-08 3.35922986E-08 0.00000000E+00 0.00000000E+00 0.00000000E+00 94 | 10 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 95 | 10 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 96 | 10 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 1.00000000E+00 0.00000000E+00 97 | 11 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 98 | 11 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 99 | 11 3 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 1.00000000E+00 100 | 12 1-1.99829456E-08-4.97327040E-08 4.86055260E-08-0.00000000E+00-0.00000000E+00 101 | 12 2-0.00000000E+00-0.00000000E+00-0.00000000E+00-0.00000000E+00-5.76289572E-01 102 | 12 3-4.19610643E-01 9.95900215E-01-0.00000000E+00-0.00000000E+00-0.00000000E+00 103 | 13 1 1.11228192E-08 2.75376324E-08-2.71989707E-08 0.00000000E+00 0.00000000E+00 104 | 13 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-8.17245574E-01 105 | 13 3 9.07704197E-01-9.04586222E-02 0.00000000E+00 0.00000000E+00 0.00000000E+00 106 | 14 1 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 107 | 14 2 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 108 | 14 3 0.00000000E+00 0.00000000E+00 1.00000000E+00 0.00000000E+00 0.00000000E+00 109 | $END 110 | POPULATION ANALYSIS 111 | NE 10.00000 -0.00000 10.00000 0.00000 112 | MOMENTS AT POINT 1 X,Y,Z= 0.000000 0.000000 0.000000 113 | DIPOLE 0.000000 0.000000 0.000000 114 | -------------------------------------------------------------------------------- /doc/source/notebooks/GamessUS_tutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Gamess(US) tutorial\n", 8 | "\n", 9 | "The `gamessus` module contains the `GamessUS` convenience class, which is python wrapper for running the [Gamess(US)](http://www.msg.ameslab.gov/GAMESS/) program with methods for writing input files, running the calculations and parsing the output files. \n" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 1, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "from chemtools.calculators.gamessus import GamessUS, GamessLogParser" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "## GamessUS wrapper" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "Now we instantiate the object by calling `Gamess` with arguments corresponding to the local installation of GAMESS(US)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 5, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "gamess = GamessUS(exevar=\"GAMESS_EXE\",\n", 42 | " version=\"00\",\n", 43 | " runopts=[\"1\"],\n", 44 | " scratch=\"/home/lmentel/scratch\")" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 6, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "data": { 54 | "text/plain": [ 55 | "'/home/lmentel/Programs/gamess-us-aug2016/rungms'" 56 | ] 57 | }, 58 | "execution_count": 6, 59 | "metadata": {}, 60 | "output_type": "execute_result" 61 | } 62 | ], 63 | "source": [ 64 | "gamess.rungms" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 7, 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "inpstr = \"\"\" $CONTRL scftyp=rhf runtyp=energy maxit=30 mult=1 ispher=1\n", 74 | " itol=30 icut=30 units=bohr cityp=guga qmttol=1.0e-8 $END\n", 75 | " $SYSTEM timlim=525600 mwords=100 $END\n", 76 | " $SCF dirscf=.false. $END\n", 77 | " $CIDRT iexcit=2 nfzc=0 ndoc=1 nval=27 group=d2h stsym=ag\n", 78 | " mxnint=14307305 $END\n", 79 | " $GUGDIA prttol=1.0e-6 cvgtol=1.0e-10 $END\n", 80 | " $DATA\n", 81 | "H2 cc-pVTZ\n", 82 | "dnh 2\n", 83 | "\n", 84 | "H 1.00 0.000000 0.000000 0.700000\n", 85 | "S 3\n", 86 | " 1 33.8700000 0.0060680 \n", 87 | " 2 5.0950000 0.0453080 \n", 88 | " 3 1.1590000 0.2028220 \n", 89 | "S 1\n", 90 | " 1 0.3258000 1.0000000 \n", 91 | "S 1\n", 92 | " 1 0.1027000 1.0000000 \n", 93 | "P 1\n", 94 | " 1 1.4070000 1.0000000 \n", 95 | "P 1\n", 96 | " 1 0.3880000 1.0000000 \n", 97 | "D 1\n", 98 | " 1 1.0570000 1.0000000 \n", 99 | "\n", 100 | " $END\n", 101 | "\"\"\"" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "Write the input file" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 8, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "inpfile = \"h2_eq_pvtz_fci.inp\"\n", 118 | "with open(inpfile, 'w') as inp:\n", 119 | " inp.write(inpstr)" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "Run the calculation" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 12, 132 | "metadata": {}, 133 | "outputs": [], 134 | "source": [ 135 | "logfile = gamess.run(inpfile)" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 13, 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "data": { 145 | "text/plain": [ 146 | "'h2_eq_pvtz_fci.log'" 147 | ] 148 | }, 149 | "execution_count": 13, 150 | "metadata": {}, 151 | "output_type": "execute_result" 152 | } 153 | ], 154 | "source": [ 155 | "logfile" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "## Parsing the results\n", 163 | "\n", 164 | "`GamessUS` has only rudimentary parsing methods implemented for the purpouses of being compliant with basis set optimizer API, however there is a dedicated parser class implemented in `chemtools` called `GamessLogParser`. There is also a separate class wrapper to parsing and writing Gamess(US) input files, and another one for reading binary files produced during the calculation such as integral files and the dictionary file." 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 15, 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "data": { 174 | "text/plain": [ 175 | "True" 176 | ] 177 | }, 178 | "execution_count": 15, 179 | "metadata": {}, 180 | "output_type": "execute_result" 181 | } 182 | ], 183 | "source": [ 184 | "gamess.accomplished(logfile)" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 14, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "data": { 194 | "text/plain": [ 195 | "-1.1329605255" 196 | ] 197 | }, 198 | "execution_count": 14, 199 | "metadata": {}, 200 | "output_type": "execute_result" 201 | } 202 | ], 203 | "source": [ 204 | "gamess.parse(logfile, 'hf total energy')" 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 16, 210 | "metadata": {}, 211 | "outputs": [ 212 | { 213 | "data": { 214 | "text/plain": [ 215 | "-1.1723345936" 216 | ] 217 | }, 218 | "execution_count": 16, 219 | "metadata": {}, 220 | "output_type": "execute_result" 221 | } 222 | ], 223 | "source": [ 224 | "gamess.parse(logfile, \"cisd total energy\")" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": 18, 230 | "metadata": {}, 231 | "outputs": [ 232 | { 233 | "data": { 234 | "text/plain": [ 235 | "-0.039374068100000104" 236 | ] 237 | }, 238 | "execution_count": 18, 239 | "metadata": {}, 240 | "output_type": "execute_result" 241 | } 242 | ], 243 | "source": [ 244 | "gamess.parse(logfile, \"correlation energy\")" 245 | ] 246 | }, 247 | { 248 | "cell_type": "code", 249 | "execution_count": 17, 250 | "metadata": {}, 251 | "outputs": [ 252 | { 253 | "data": { 254 | "text/plain": [ 255 | "82.0" 256 | ] 257 | }, 258 | "execution_count": 17, 259 | "metadata": {}, 260 | "output_type": "execute_result" 261 | } 262 | ], 263 | "source": [ 264 | "gamess.parse(logfile, 'regexp', r'NUMBER OF CONFIGURATIONS\\s*=\\s*(\\d+)')" 265 | ] 266 | }, 267 | { 268 | "cell_type": "code", 269 | "execution_count": 19, 270 | "metadata": {}, 271 | "outputs": [ 272 | { 273 | "data": { 274 | "application/json": { 275 | "Software versions": [ 276 | { 277 | "module": "Python", 278 | "version": "3.6.3 64bit [GCC 7.2.0]" 279 | }, 280 | { 281 | "module": "IPython", 282 | "version": "6.2.1" 283 | }, 284 | { 285 | "module": "OS", 286 | "version": "Linux 4.9.0 4 amd64 x86_64 with debian 9.1" 287 | }, 288 | { 289 | "module": "chemtools", 290 | "version": "0.8.4" 291 | } 292 | ] 293 | }, 294 | "text/html": [ 295 | "
SoftwareVersion
Python3.6.3 64bit [GCC 7.2.0]
IPython6.2.1
OSLinux 4.9.0 4 amd64 x86_64 with debian 9.1
chemtools0.8.4
Mon Nov 27 19:27:43 2017 CET
" 296 | ], 297 | "text/latex": [ 298 | "\\begin{tabular}{|l|l|}\\hline\n", 299 | "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", 300 | "Python & 3.6.3 64bit [GCC 7.2.0] \\\\ \\hline\n", 301 | "IPython & 6.2.1 \\\\ \\hline\n", 302 | "OS & Linux 4.9.0 4 amd64 x86\\_64 with debian 9.1 \\\\ \\hline\n", 303 | "chemtools & 0.8.4 \\\\ \\hline\n", 304 | "\\hline \\multicolumn{2}{|l|}{Mon Nov 27 19:27:43 2017 CET} \\\\ \\hline\n", 305 | "\\end{tabular}\n" 306 | ], 307 | "text/plain": [ 308 | "Software versions\n", 309 | "Python 3.6.3 64bit [GCC 7.2.0]\n", 310 | "IPython 6.2.1\n", 311 | "OS Linux 4.9.0 4 amd64 x86_64 with debian 9.1\n", 312 | "chemtools 0.8.4\n", 313 | "Mon Nov 27 19:27:43 2017 CET" 314 | ] 315 | }, 316 | "execution_count": 19, 317 | "metadata": {}, 318 | "output_type": "execute_result" 319 | } 320 | ], 321 | "source": [ 322 | "%version_information chemtools" 323 | ] 324 | } 325 | ], 326 | "metadata": { 327 | "kernelspec": { 328 | "display_name": "Python 3", 329 | "language": "python", 330 | "name": "python3" 331 | }, 332 | "language_info": { 333 | "codemirror_mode": { 334 | "name": "ipython", 335 | "version": 3 336 | }, 337 | "file_extension": ".py", 338 | "mimetype": "text/x-python", 339 | "name": "python", 340 | "nbconvert_exporter": "python", 341 | "pygments_lexer": "ipython3", 342 | "version": "3.6.3" 343 | } 344 | }, 345 | "nbformat": 4, 346 | "nbformat_minor": 1 347 | } 348 | -------------------------------------------------------------------------------- /chemtools/cbs.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | '''Module for Complete Basis Set (CBS) Extrapolations.''' 26 | 27 | from scipy.optimize import curve_fit 28 | import numpy as np 29 | 30 | 31 | def extrapolate(x, energy, method, **kwargs): 32 | ''' 33 | An interface for performing CBS extrapolations using various methods. 34 | 35 | Args: 36 | x : numpy.array 37 | A vector of basis set cardinal numbers 38 | energy : numpy.array 39 | A vector of corresponding energies 40 | method : str 41 | Method/formula to use to perform the extrapolation 42 | 43 | Kwargs: 44 | Keyword arguments to be passed to the requested extrapolation function 45 | using the `method` argument 46 | ''' 47 | 48 | methods = { 49 | 'poly': poly, 50 | 'expo': expo, 51 | 'exposqrt': exposqrt, 52 | 'exposum': exposum, 53 | 'uste': uste, 54 | } 55 | 56 | if len(x) != len(energy): 57 | raise ValueError("x and energy should have the same size") 58 | 59 | if method in methods.keys(): 60 | eopt, ecov = curve_fit(methods[method](**kwargs), x, energy) 61 | return eopt 62 | else: 63 | raise ValueError("wrong method: {0}, accepted values are: {1}".format(method, 64 | ", ".join(list(methods.keys())))) 65 | 66 | 67 | def uste(method="CI"): 68 | ''' 69 | CBS extrapolation using uniform singlet and triplet pair extrapolation 70 | (USTE) scheme [Varandas2007]_. 71 | 72 | .. [Varandas2007] Varandas, A. J. C. (2007). "Extrapolating to the one-electron 73 | basis-set limit in electronic structure calculations. The Journal of 74 | Chemical Physics, 126(24), 244105. `doi:10.1063/1.2741259 `_ 75 | 76 | Args: 77 | x : int 78 | Cardinal number of the basis set 79 | e_cbs : float 80 | Approximation to the energy value at the CBS limit 81 | a : float 82 | Empirical A3 parameter 83 | method : str 84 | One of: *ci*, *cc* 85 | 86 | Returns: 87 | function object 88 | ''' 89 | def uste_ci(x, e_cbs, a): 90 | # parameters calibrated for MRCI(Q) 91 | params = { 92 | "A05": 0.003769, 93 | "c": -1.1784771, 94 | "m": 1.25, 95 | "alpha": -0.375} 96 | 97 | a5 = params["A05"] + params['c'] * np.power(a, params["m"]) 98 | v = e_cbs + a / np.power(x + params["alpha"], 3) + a5 / np.power(x + params["alpha"], 5) 99 | return v 100 | 101 | def uste_cc(x, e_cbs, a): 102 | # parameters calibrated for CC 103 | params = { 104 | "A05": 0.1660699, 105 | "c": -1.4222512, 106 | "m": 1.0, 107 | "alpha": -0.375} 108 | 109 | a5 = params["A05"] + params['c'] * np.power(a, params["m"]) 110 | v = e_cbs + a / np.power(x + params["alpha"], 3) + a5 / np.power(x + params["alpha"], 5) 111 | return v 112 | 113 | if method.lower() == "ci": 114 | return uste_ci 115 | elif method.lower() == "cc": 116 | return uste_cc 117 | else: 118 | ValueError("wrong method: {}, accepted values are: 'ci', 'cc'".format(method)) 119 | 120 | 121 | def exposqrt(twopoint=True): 122 | ''' 123 | Three-point formula for extrapolating the HF reference energy [2]_. 124 | 125 | .. [2] Karton, A., & Martin, J. M. L. (2006). Comment on: “Estimating the 126 | Hartree-Fock limit from finite basis set calculations” [Jensen F (2005) 127 | Theor Chem Acc 113:267]. Theoretical Chemistry Accounts, 115, 330–333. 128 | `doi:10.1007/s00214-005-0028-6 `_ 129 | 130 | .. math:: 131 | 132 | E^{HF}(X) = E_{CBS} + a\cdot \exp(-b\sqrt{X}) 133 | 134 | Args: 135 | twpoint : bool 136 | A flag marking the use of two point extrapolation with `b=9.0` 137 | 138 | Returns: 139 | funtion object 140 | ''' 141 | 142 | def exposqrt2(x, e_cbs, a): 143 | ''' 144 | Two-point formula for extrapolating the HF reference energy, as 145 | proposed by A. Karton and J. M. L. Martin, Theor. Chem. Acc. 115, 330. 146 | (2006) 147 | 148 | :math:`E^{HF}(X) = E_{CBS} + A\cdot \exp(-9\sqrt{X})` 149 | 150 | Args: 151 | x : int 152 | Cardinal number of the basis set 153 | e_cbs : float 154 | Approximation to the energy value at the CBS limit 155 | a : float 156 | Pre-exponential empirical parameter 157 | ''' 158 | return e_cbs + a * np.exp(-9.0 * np.sqrt(x)) 159 | 160 | def exposqrt3(x, e_cbs, a, b): 161 | ''' 162 | Three-point formula for extrapolating the HF reference energy, as 163 | proposed by A. Karton and J. M. L. Martin, Theor. Chem. Acc. 115, 330. 164 | (2006) 165 | 166 | :math:`E^{HF}(X) = E_{CBS} + A\cdot \exp(-B\sqrt{X})` 167 | 168 | Args: 169 | x : int 170 | Cardinal number of the basis set 171 | e_cbs : float 172 | Approximation to the energy value at the CBS limit 173 | a : float 174 | Pre-exponential empirical parameter 175 | b : float 176 | Exponential empirical parameter 177 | ''' 178 | return e_cbs + a * np.exp(-b * np.sqrt(x)) 179 | 180 | if twopoint: 181 | return exposqrt2 182 | else: 183 | return exposqrt3 184 | 185 | 186 | def expo(): 187 | ''' 188 | CBS extrapolation formula by exponential Dunning-Feller relation. 189 | 190 | .. math:: 191 | 192 | E^{HF}(X) = E_{CBS} + a\cdot\exp(-bX) 193 | 194 | Returns: 195 | function object 196 | ''' 197 | 198 | def exponential(x, e_cbs, a, b): 199 | ''' 200 | CBS extrapolation formula by exponential Dunning-Feller relation. 201 | 202 | Args: 203 | x : int 204 | Cardinal number of the basis set 205 | e_cbs : float 206 | Approximation to the energy value at the CBS limit 207 | a : float 208 | Pre-exponential empirical parameter 209 | b : float 210 | Exponential empirical parameter 211 | ''' 212 | 213 | return e_cbs + b * np.exp(-a * x) 214 | 215 | return exponential 216 | 217 | 218 | def exposum(): 219 | ''' 220 | Three point extrapolation through sum of exponentials expression 221 | 222 | .. math:: 223 | 224 | E(X) = E_{CBS} + a \cdot\exp(-(X-1)) + b\cdot\exp(-(X-1)^2) 225 | 226 | ''' 227 | 228 | def exponentialssum(x, e_cbs, a, b): 229 | ''' 230 | Three point extrapolation through sum of exponentials expression 231 | 232 | :math:`E(X) = E_{CBS} + A \cdot\exp(-(X-1)) + B\cdot\exp(-(X-1)^2)` 233 | 234 | Args: 235 | x : int 236 | Cardinal number of the basis set 237 | e_cbs : float 238 | Approximation to the energy value at the CBS limit 239 | a : float 240 | Empirical coefficent 241 | b : float 242 | Empirical coefficent 243 | ''' 244 | return e_cbs + a * np.exp(-(x - 1)) + b * np.exp(-(x - 1)**2) 245 | 246 | return exponentialssum 247 | 248 | 249 | def poly(p=0.0, z=3.0, twopoint=True): 250 | ''' 251 | CBS extrapolation by polynomial relation. 252 | 253 | .. math:: 254 | 255 | E(X) = E_{CBS} + \sum_{i}a_{i}\cdot (X + P)^{-b_{i}} 256 | 257 | Kwargs: 258 | twpoint : bool 259 | A flag for choosing the two point extrapolation 260 | z : float or list of floats 261 | Order of the polynomial, *default=3.0* 262 | p : float 263 | A parameter modifying the cardinal number, *default=0.0* 264 | ''' 265 | 266 | def poly3(x, e_cbs, a, z): 267 | ''' 268 | Args: 269 | x : int 270 | Cardinal number of the basis set 271 | e_cbs : float 272 | Approximation to the energy value at the CBS limit 273 | a : float or list of floats 274 | Polynomial coefficient 275 | ''' 276 | 277 | a = np.array(a) 278 | z = np.array(z) 279 | return e_cbs + np.dot(a, np.power((x + p), -z)) 280 | 281 | def poly2(x, e_cbs, a): 282 | ''' 283 | Args: 284 | x : int 285 | Cardinal number of the basis set 286 | e_cbs : float 287 | Approximation to the energy value at the CBS limit 288 | a : float or list of floats 289 | Polynomial coefficient 290 | ''' 291 | 292 | a = np.array(a) 293 | zeta = np.array(z) 294 | return e_cbs + np.dot(a, np.power((x + p), -zeta)) 295 | 296 | if twopoint: 297 | return poly2 298 | else: 299 | return poly3 300 | -------------------------------------------------------------------------------- /doc/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # chemtools documentation build configuration file, created by 4 | # sphinx-quickstart on Fri May 9 00:02:00 2014. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import os 16 | import sys 17 | import inspect 18 | import guzzle_sphinx_theme 19 | 20 | 21 | autodoc_mock_imports = [ 22 | 'argparse', 23 | 'mendeleev', 24 | 'numba' 25 | 'numpy', 26 | 'pandas', 27 | 'scipy', 28 | 'sqlalchemy', 29 | ] 30 | 31 | __location__ = os.path.join(os.getcwd(), os.path.dirname( 32 | inspect.getfile(inspect.currentframe()))) 33 | 34 | module_dir = os.path.normpath(os.path.join(__location__, "../../")) 35 | sys.path.insert(0, os.path.abspath(module_dir)) 36 | 37 | # -- General configuration ------------------------------------------------ 38 | 39 | # If your documentation needs a minimal Sphinx version, state it here. 40 | #needs_sphinx = '1.0' 41 | 42 | # Add any Sphinx extension module names here, as strings. They can be 43 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 44 | # ones. 45 | extensions = [ 46 | 'sphinx.ext.autodoc', 47 | 'sphinx.ext.intersphinx', 48 | 'sphinx.ext.todo', 49 | 'sphinx.ext.autosummary', 50 | 'sphinx.ext.viewcode', 51 | 'sphinx.ext.mathjax', 52 | 'sphinx.ext.ifconfig', 53 | 'nbsphinx', 54 | 'IPython.sphinxext.ipython_console_highlighting' 55 | ] 56 | 57 | # MathJax path for rendering the formulas 58 | mathjax_path = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" 59 | 60 | # Add any paths that contain templates here, relative to this directory. 61 | templates_path = ['_templates'] 62 | 63 | # The suffix of source filenames. 64 | source_suffix = '.rst' 65 | 66 | # The encoding of source files. 67 | #source_encoding = 'utf-8-sig' 68 | 69 | # The master toctree document. 70 | master_doc = 'index' 71 | 72 | # General information about the project. 73 | project = u'chemtools' 74 | copyright = u'2014, Lukasz Mentel' 75 | 76 | # The version info for the project you're documenting, acts as replacement for 77 | # |version| and |release|, also used in various other places throughout the 78 | # built documents. 79 | # 80 | # The short X.Y version. 81 | version = '0.9.2' 82 | # The full version, including alpha/beta/rc tags. 83 | release = '0.9.2' 84 | 85 | # The language for content autogenerated by Sphinx. Refer to documentation 86 | # for a list of supported languages. 87 | #language = None 88 | 89 | # There are two options for replacing |today|: either, you set today to some 90 | # non-false value, then it is used: 91 | #today = '' 92 | # Else, today_fmt is used as the format for a strftime call. 93 | #today_fmt = '%B %d, %Y' 94 | 95 | # List of patterns, relative to source directory, that match files and 96 | # directories to ignore when looking for source files. 97 | exclude_patterns = ['_build', 'build', '**.ipynb_checkpoints'] 98 | 99 | # The reST default role (used for this markup: `text`) to use for all 100 | # documents. 101 | #default_role = None 102 | 103 | # If true, '()' will be appended to :func: etc. cross-reference text. 104 | #add_function_parentheses = True 105 | 106 | # If true, the current module name will be prepended to all description 107 | # unit titles (such as .. function::). 108 | add_module_names = False 109 | 110 | # If true, sectionauthor and moduleauthor directives will be shown in the 111 | # output. They are ignored by default. 112 | #show_authors = False 113 | 114 | # The name of the Pygments (syntax highlighting) style to use. 115 | pygments_style = 'sphinx' 116 | 117 | # A list of ignored prefixes for module index sorting. 118 | #modindex_common_prefix = [] 119 | 120 | # If true, keep warnings as "system message" paragraphs in the built documents. 121 | #keep_warnings = False 122 | 123 | 124 | # -- Options for HTML output ---------------------------------------------- 125 | 126 | # The theme to use for HTML and HTML Help pages. See the documentation for 127 | # a list of builtin themes. 128 | 129 | html_theme = 'guzzle_sphinx_theme' 130 | extensions.append("guzzle_sphinx_theme") 131 | # Theme options are theme-specific and customize the look and feel of a theme 132 | # further. For a list of options available for each theme, see the 133 | # documentation. 134 | html_theme_options = { 135 | # Set the name of the project to appear in the sidebar 136 | "project_nav_name": "chemtools", 137 | } 138 | # Add any paths that contain custom themes here, relative to this directory. 139 | html_theme_path = guzzle_sphinx_theme.html_theme_path() 140 | 141 | # The name for this set of Sphinx documents. If None, it defaults to 142 | # " v documentation". 143 | #html_title = None 144 | 145 | # A shorter title for the navigation bar. Default is the same as html_title. 146 | #html_short_title = None 147 | 148 | # The name of an image file (relative to this directory) to place at the top 149 | # of the sidebar. 150 | #html_logo = None 151 | 152 | # The name of an image file (within the static path) to use as favicon of the 153 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 154 | # pixels large. 155 | #html_favicon = None 156 | 157 | # Add any paths that contain custom static files (such as style sheets) here, 158 | # relative to this directory. They are copied after the builtin static files, 159 | # so a file named "default.css" will overwrite the builtin "default.css". 160 | #html_static_path = ['_static'] 161 | 162 | # Add any extra paths that contain custom files (such as robots.txt or 163 | # .htaccess) here, relative to this directory. These files are copied 164 | # directly to the root of the documentation. 165 | #html_extra_path = [] 166 | 167 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 168 | # using the given strftime format. 169 | #html_last_updated_fmt = '%b %d, %Y' 170 | 171 | # If true, SmartyPants will be used to convert quotes and dashes to 172 | # typographically correct entities. 173 | #html_use_smartypants = True 174 | 175 | # Custom sidebar templates, maps document names to template names. 176 | #html_sidebars = {} 177 | 178 | # Additional templates that should be rendered to pages, maps page names to 179 | # template names. 180 | #html_additional_pages = {} 181 | 182 | # If false, no module index is generated. 183 | #html_domain_indices = True 184 | 185 | # If false, no index is generated. 186 | html_use_index = True 187 | 188 | # If true, the index is split into individual pages for each letter. 189 | #html_split_index = False 190 | 191 | # If true, links to the reST sources are added to the pages. 192 | #html_show_sourcelink = True 193 | 194 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 195 | #html_show_sphinx = True 196 | 197 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 198 | #html_show_copyright = True 199 | 200 | # If true, an OpenSearch description file will be output, and all pages will 201 | # contain a tag referring to it. The value of this option must be the 202 | # base URL from which the finished HTML is served. 203 | #html_use_opensearch = '' 204 | 205 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 206 | #html_file_suffix = None 207 | 208 | # Output file base name for HTML help builder. 209 | htmlhelp_basename = 'chemtoolsdoc' 210 | 211 | 212 | # -- Options for LaTeX output --------------------------------------------- 213 | 214 | latex_elements = { 215 | # The paper size ('letterpaper' or 'a4paper'). 216 | #'papersize': 'letterpaper', 217 | 218 | # The font size ('10pt', '11pt' or '12pt'). 219 | #'pointsize': '10pt', 220 | 221 | # Additional stuff for the LaTeX preamble. 222 | #'preamble': '', 223 | } 224 | 225 | # Grouping the document tree into LaTeX files. List of tuples 226 | # (source start file, target name, title, 227 | # author, documentclass [howto, manual, or own class]). 228 | latex_documents = [ 229 | ('index', 'chemtools.tex', u'chemtools Documentation', 230 | u'Lukasz Mentel', 'manual'), 231 | ] 232 | 233 | # The name of an image file (relative to this directory) to place at the top of 234 | # the title page. 235 | #latex_logo = None 236 | 237 | # For "manual" documents, if this is true, then toplevel headings are parts, 238 | # not chapters. 239 | #latex_use_parts = False 240 | 241 | # If true, show page references after internal links. 242 | #latex_show_pagerefs = False 243 | 244 | # If true, show URL addresses after external links. 245 | #latex_show_urls = False 246 | 247 | # Documents to append as an appendix to all manuals. 248 | #latex_appendices = [] 249 | 250 | # If false, no module index is generated. 251 | #latex_domain_indices = True 252 | 253 | 254 | # -- Options for manual page output --------------------------------------- 255 | 256 | # One entry per manual page. List of tuples 257 | # (source start file, name, description, authors, manual section). 258 | man_pages = [ 259 | ('index', 'chemtools', u'chemtools Documentation', 260 | [u'Lukasz Mentel'], 1) 261 | ] 262 | 263 | # If true, show URL addresses after external links. 264 | #man_show_urls = False 265 | 266 | 267 | # -- Options for Texinfo output ------------------------------------------- 268 | 269 | # Grouping the document tree into Texinfo files. List of tuples 270 | # (source start file, target name, title, author, 271 | # dir menu entry, description, category) 272 | texinfo_documents = [ 273 | ('index', 'chemtools', u'chemtools Documentation', 274 | u'Lukasz Mentel', 'chemtools', 'One line description of project.', 275 | 'Miscellaneous'), 276 | ] 277 | 278 | # Documents to append as an appendix to all manuals. 279 | #texinfo_appendices = [] 280 | 281 | # If false, no module index is generated. 282 | #texinfo_domain_indices = True 283 | 284 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 285 | #texinfo_show_urls = 'footnote' 286 | 287 | # If true, do not generate a @detailmenu in the "Top" node's menu. 288 | #texinfo_no_detailmenu = False 289 | -------------------------------------------------------------------------------- /tests/test_basisset/test_basisset_parsers.py: -------------------------------------------------------------------------------- 1 | AUGTZ_MOLPRO = '''basis={ 2 | ! 3 | ! HYDROGEN (5s,2p) -> [3s,2p] 4 | ! HYDROGEN (4s,1p) -> [2s,1p] 5 | ! HYDROGEN (1s,1p) 6 | s, H , 13.0100000, 1.9620000, 0.4446000, 0.1220000, 0.0297400 7 | c, 1.3, 0.0196850, 0.1379770, 0.4781480 8 | c, 4.4, 1 9 | c, 5.5, 1 10 | p, H , 0.7270000, 0.1410000 11 | c, 1.1, 1 12 | c, 2.2, 1 13 | ! LITHIUM (10s,5p,2d) -> [4s,3p,2d] 14 | ! LITHIUM (9s,4p,1d) -> [3s,2p,1d] 15 | ! LITHIUM (1s,1p,1d) 16 | s, LI , 1469.0000000, 220.5000000, 50.2600000, 14.2400000, 4.5810000, 1.5800000, 0.5640000, 0.0734500, 0.0280500, 0.0086400 17 | c, 1.8, 0.0007660, 0.0058920, 0.0296710, 0.1091800, 0.2827890, 0.4531230, 0.2747740, 0.0097510 18 | c, 1.8, -0.0001200, -0.0009230, -0.0046890, -0.0176820, -0.0489020, -0.0960090, -0.1363800, 0.5751020 19 | c, 9.9, 1 20 | c, 10.10, 1 21 | p, LI , 1.5340000, 0.2749000, 0.0736200, 0.0240300, 0.0057900 22 | c, 1.3, 0.0227840, 0.1391070, 0.5003750 23 | c, 4.4, 1 24 | c, 5.5, 1 25 | d, LI , 0.1239000, 0.0725000 26 | c, 1.1, 1 27 | c, 2.2, 1 28 | ! BERYLLIUM (10s,5p,2d) -> [4s,3p,2d] 29 | ! BERYLLIUM (9s,4p,1d) -> [3s,2p,1d] 30 | ! BERYLLIUM (1s,1p,1d) 31 | s, BE , 2940.0000000, 441.2000000, 100.5000000, 28.4300000, 9.1690000, 3.1960000, 1.1590000, 0.1811000, 0.0589000, 0.0187700 32 | c, 1.8, 0.0006800, 0.0052360, 0.0266060, 0.0999930, 0.2697020, 0.4514690, 0.2950740, 0.0125870 33 | c, 1.8, -0.0001230, -0.0009660, -0.0048310, -0.0193140, -0.0532800, -0.1207230, -0.1334350, 0.5307670 34 | c, 9.9, 1 35 | c, 10.10, 1 36 | p, BE , 3.6190000, 0.7110000, 0.1951000, 0.0601800, 0.0085000 37 | c, 1.3, 0.0291110, 0.1693650, 0.5134580 38 | c, 4.4, 1 39 | c, 5.5, 1 40 | d, BE , 0.2380000, 0.0740000 41 | c, 1.1, 1 42 | c, 2.2, 1 43 | }''' 44 | 45 | AUGTZ_GAMESS = '''$DATA 46 | HYDROGEN 47 | S 3 48 | 1 13.0100000 0.0196850 49 | 2 1.9620000 0.1379770 50 | 3 0.4446000 0.4781480 51 | S 1 52 | 1 0.1220000 1.0000000 53 | S 1 54 | 1 0.0297400 1.0000000 55 | P 1 56 | 1 0.7270000 1.0000000 57 | P 1 58 | 1 0.1410000 1.0000000 59 | 60 | LITHIUM 61 | S 8 62 | 1 1469.0000000 0.0007660 63 | 2 220.5000000 0.0058920 64 | 3 50.2600000 0.0296710 65 | 4 14.2400000 0.1091800 66 | 5 4.5810000 0.2827890 67 | 6 1.5800000 0.4531230 68 | 7 0.5640000 0.2747740 69 | 8 0.0734500 0.0097510 70 | S 8 71 | 1 1469.0000000 -0.0001200 72 | 2 220.5000000 -0.0009230 73 | 3 50.2600000 -0.0046890 74 | 4 14.2400000 -0.0176820 75 | 5 4.5810000 -0.0489020 76 | 6 1.5800000 -0.0960090 77 | 7 0.5640000 -0.1363800 78 | 8 0.0734500 0.5751020 79 | S 1 80 | 1 0.0280500 1.0000000 81 | S 1 82 | 1 0.0086400 1.0000000 83 | P 3 84 | 1 1.5340000 0.0227840 85 | 2 0.2749000 0.1391070 86 | 3 0.0736200 0.5003750 87 | P 1 88 | 1 0.0240300 1.0000000 89 | P 1 90 | 1 0.0057900 1.0000000 91 | D 1 92 | 1 0.1239000 1.0000000 93 | D 1 94 | 1 0.0725000 1.0000000 95 | 96 | BERYLLIUM 97 | S 8 98 | 1 2940.0000000 0.0006800 99 | 2 441.2000000 0.0052360 100 | 3 100.5000000 0.0266060 101 | 4 28.4300000 0.0999930 102 | 5 9.1690000 0.2697020 103 | 6 3.1960000 0.4514690 104 | 7 1.1590000 0.2950740 105 | 8 0.1811000 0.0125870 106 | S 8 107 | 1 2940.0000000 -0.0001230 108 | 2 441.2000000 -0.0009660 109 | 3 100.5000000 -0.0048310 110 | 4 28.4300000 -0.0193140 111 | 5 9.1690000 -0.0532800 112 | 6 3.1960000 -0.1207230 113 | 7 1.1590000 -0.1334350 114 | 8 0.1811000 0.5307670 115 | S 1 116 | 1 0.0589000 1.0000000 117 | S 1 118 | 1 0.0187700 1.0000000 119 | P 3 120 | 1 3.6190000 0.0291110 121 | 2 0.7110000 0.1693650 122 | 3 0.1951000 0.5134580 123 | P 1 124 | 1 0.0601800 1.0000000 125 | P 1 126 | 1 0.0085000 1.0000000 127 | D 1 128 | 1 0.2380000 1.0000000 129 | D 1 130 | 1 0.0740000 1.0000000 131 | $END''' 132 | 133 | AUGTZ_GAUSSIAN = '''**** 134 | H 0 135 | S 3 1.00 136 | 13.0100000 0.0196850 137 | 1.9620000 0.1379770 138 | 0.4446000 0.4781480 139 | S 1 1.00 140 | 0.1220000 1.0000000 141 | S 1 1.00 142 | 0.0297400 1.0000000 143 | P 1 1.00 144 | 0.7270000 1.0000000 145 | P 1 1.00 146 | 0.1410000 1.0000000 147 | **** 148 | Li 0 149 | S 8 1.00 150 | 1469.0000000 0.0007660 151 | 220.5000000 0.0058920 152 | 50.2600000 0.0296710 153 | 14.2400000 0.1091800 154 | 4.5810000 0.2827890 155 | 1.5800000 0.4531230 156 | 0.5640000 0.2747740 157 | 0.0734500 0.0097510 158 | S 8 1.00 159 | 1469.0000000 -0.0001200 160 | 220.5000000 -0.0009230 161 | 50.2600000 -0.0046890 162 | 14.2400000 -0.0176820 163 | 4.5810000 -0.0489020 164 | 1.5800000 -0.0960090 165 | 0.5640000 -0.1363800 166 | 0.0734500 0.5751020 167 | S 1 1.00 168 | 0.0280500 1.0000000 169 | S 1 1.00 170 | 0.0086400 1.0000000 171 | P 3 1.00 172 | 1.5340000 0.0227840 173 | 0.2749000 0.1391070 174 | 0.0736200 0.5003750 175 | P 1 1.00 176 | 0.0240300 1.0000000 177 | P 1 1.00 178 | 0.0057900 1.0000000 179 | D 1 1.00 180 | 0.1239000 1.0000000 181 | D 1 1.00 182 | 0.0725000 1.0000000 183 | **** 184 | Be 0 185 | S 8 1.00 186 | 2940.0000000 0.0006800 187 | 441.2000000 0.0052360 188 | 100.5000000 0.0266060 189 | 28.4300000 0.0999930 190 | 9.1690000 0.2697020 191 | 3.1960000 0.4514690 192 | 1.1590000 0.2950740 193 | 0.1811000 0.0125870 194 | S 8 1.00 195 | 2940.0000000 -0.0001230 196 | 441.2000000 -0.0009660 197 | 100.5000000 -0.0048310 198 | 28.4300000 -0.0193140 199 | 9.1690000 -0.0532800 200 | 3.1960000 -0.1207230 201 | 1.1590000 -0.1334350 202 | 0.1811000 0.5307670 203 | S 1 1.00 204 | 0.0589000 1.0000000 205 | S 1 1.00 206 | 0.0187700 1.0000000 207 | P 3 1.00 208 | 3.6190000 0.0291110 209 | 0.7110000 0.1693650 210 | 0.1951000 0.5134580 211 | P 1 1.00 212 | 0.0601800 1.0000000 213 | P 1 1.00 214 | 0.0085000 1.0000000 215 | D 1 1.00 216 | 0.2380000 1.0000000 217 | D 1 1.00 218 | 0.0740000 1.0000000 219 | ****''' 220 | 221 | from chemtools.basisset import BasisSet 222 | 223 | def test_basis_set_parser_molpro(tmpdir): 224 | 225 | tmpdir.chdir() 226 | fpath = tmpdir.join('augtz.molpro') 227 | fpath.write(AUGTZ_MOLPRO) 228 | 229 | bsd = BasisSet.from_file(str(fpath), fmt='molpro') 230 | assert isinstance(bsd, dict) 231 | assert 'H' in bsd.keys() 232 | assert 'Li' in bsd.keys() 233 | assert 'Be' in bsd.keys() 234 | assert isinstance(bsd['H'], BasisSet) 235 | assert isinstance(bsd['Li'], BasisSet) 236 | assert isinstance(bsd['Be'], BasisSet) 237 | assert bsd['H'].nf() == 9 238 | assert bsd['Li'].nf() == 23 239 | assert bsd['Be'].nf() == 23 240 | 241 | def test_basis_set_parser_gamess(tmpdir): 242 | 243 | tmpdir.chdir() 244 | fpath = tmpdir.join('augtz.gamess') 245 | fpath.write(AUGTZ_GAMESS) 246 | 247 | bsd = BasisSet.from_file(str(fpath), fmt='gamessus') 248 | assert isinstance(bsd, dict) 249 | assert 'H' in bsd.keys() 250 | assert 'Li' in bsd.keys() 251 | assert 'Be' in bsd.keys() 252 | assert isinstance(bsd['H'], BasisSet) 253 | assert isinstance(bsd['Li'], BasisSet) 254 | assert isinstance(bsd['Be'], BasisSet) 255 | assert bsd['H'].nf() == 9 256 | assert bsd['Li'].nf() == 23 257 | assert bsd['Be'].nf() == 23 258 | 259 | def test_basis_set_parser_gaussian(tmpdir): 260 | 261 | tmpdir.chdir() 262 | fpath = tmpdir.join('augtz.gaussian') 263 | fpath.write(AUGTZ_GAUSSIAN) 264 | 265 | bsd = BasisSet.from_file(str(fpath), fmt='gaussian') 266 | assert isinstance(bsd, dict) 267 | assert 'H' in bsd.keys() 268 | assert 'Li' in bsd.keys() 269 | assert 'Be' in bsd.keys() 270 | assert isinstance(bsd['H'], BasisSet) 271 | assert isinstance(bsd['Li'], BasisSet) 272 | assert isinstance(bsd['Be'], BasisSet) 273 | assert bsd['H'].nf() == 9 274 | assert bsd['Li'].nf() == 23 275 | assert bsd['Be'].nf() == 23 276 | 277 | -------------------------------------------------------------------------------- /chemtools/calculators/gamessorbitals.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #The MIT License (MIT) 4 | # 5 | #Copyright (c) 2014 Lukasz Mentel 6 | # 7 | #Permission is hereby granted, free of charge, to any person obtaining a copy 8 | #of this software and associated documentation files (the "Software"), to deal 9 | #in the Software without restriction, including without limitation the rights 10 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | #copies of the Software, and to permit persons to whom the Software is 12 | #furnished to do so, subject to the following conditions: 13 | # 14 | #The above copyright notice and this permission notice shall be included in all 15 | #copies or substantial portions of the Software. 16 | # 17 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | #SOFTWARE. 24 | 25 | 'Orbitals class' 26 | 27 | import numpy as np 28 | import pandas as pd 29 | 30 | from chemtools.calculators.gamessus import GamessLogParser, GamessDatParser 31 | from chemtools.calculators.gamessreader import DictionaryFile, tri2full 32 | 33 | class Orbitals(pd.DataFrame): 34 | ''' 35 | A convenience class for handling GAMESS(US) orbitals. 36 | ''' 37 | 38 | def __init__(self, *args, **kwargs): 39 | 40 | super(Orbitals, self).__init__(*args, **kwargs) 41 | 42 | @classmethod 43 | def from_files(cls, name=None, logfile=None, dictfile=None, datfile=None): 44 | ''' 45 | Initialize the `Orbitals` instance based on orbital information parsed from the `logfile` 46 | and read from the `dictfile`. 47 | 48 | Args: 49 | name : str 50 | One of `hf` or `ci` 51 | logfile : str 52 | Name of the GAMESS(US) log file 53 | dictfile : str 54 | Name of the GAMESS(US) dictionary file .F10 55 | datfile : str : 56 | Name of the GAMESS(US) dat file 57 | ''' 58 | 59 | if name == 'hf': 60 | evec_record = 15 61 | eval_record = 17 62 | syml_record = 255 63 | elif name == 'ci': 64 | evec_record = 19 65 | eval_record = 21 66 | syml_record = 256 67 | elif name == 'local': 68 | pass 69 | else: 70 | raise ValueError('name should be one either "hf", "ci" or "local"') 71 | 72 | if name in ['hf', 'ci']: 73 | # parse the number of aos and mos 74 | glp = GamessLogParser(logfile) 75 | nao = glp.get_number_of_aos() 76 | nmo = glp.get_number_of_mos() 77 | 78 | # read the relevant record from the dictfile 79 | df = DictionaryFile(dictfile) 80 | # read the orbitals 81 | vector = df.read_record(evec_record) 82 | vecs = vector[:nao*nmo].reshape((nao, nmo), order='F') 83 | # read the eigenvectors 84 | evals = df.read_record(eval_record) 85 | evals = evals[:nmo] 86 | # read symmetry labels 87 | symlab = df.read_record(syml_record) 88 | symlab = symlab[:nmo] 89 | 90 | data = dict([ 91 | ('symlabels', [s.strip() for s in symlab]), 92 | ('eigenvals', evals), 93 | ('gindex', range(1, nmo + 1)), 94 | ]) 95 | elif name == 'local': 96 | gdp = GamessDatParser(datfile) 97 | vecs = gdp.get_orbitals(name) 98 | nao, nmo = vecs.shape 99 | 100 | data = dict([('gindex', range(1, nmo + 1)),]) 101 | 102 | dataframe = cls(data=data) 103 | 104 | dataframe.nao = nao 105 | dataframe.nmo = nmo 106 | dataframe.name = name 107 | dataframe.logfile = logfile 108 | dataframe.dictfile = dictfile 109 | dataframe.datfile = datfile 110 | dataframe.coeffs = pd.DataFrame(data=vecs) 111 | 112 | return dataframe 113 | 114 | def assign_lz_values(self, decimals=6, tolv=1.0e-2): 115 | ''' 116 | Determine the eigenvalues of the Lz operator for each nondegenerate or 117 | a combination of degenerate orbitals and assign them to `lzvals` column 118 | in the DataFrame 119 | 120 | The Lz integrals over atomic orbitals are read from the dictionary file 121 | record No. 379. 122 | 123 | Args: 124 | decimals : int 125 | Number of decimals to keep when comparing float eigenvalues 126 | tolv : float 127 | Threshold for keeping wights of the eiegenvalues (squared eigenvector components) 128 | 129 | WARNING: 130 | currently this only works if the eigenvalues on input are sorted 131 | ''' 132 | 133 | lzmap = {0: 'sigma', 1: 'pi', 2: 'delta', 3: 'phi'} 134 | 135 | df = DictionaryFile(self.dictfile) 136 | # read Lz integrals from the dictionary file 137 | lzvec = df.read_record(379) 138 | # expand triangular to square matrix 139 | lzints = tri2full(lzvec, sym=False) 140 | 141 | unq, indices = check_duplicates(self.eigenvals, decimals=decimals) 142 | 143 | out = [] 144 | 145 | mos = self.coeffs.values 146 | 147 | for IG, (i, j) in enumerate(indices, start=1): 148 | # transform the integrals to the MO basis 149 | lzmo = np.dot(mos[:, i:j].T, np.dot(lzints, mos[:, i:j])) 150 | 151 | # tranform to complex type 152 | lzcplx = np.zeros_like(lzmo, dtype=np.complex128) 153 | lzcplx.imag = -lzmo 154 | 155 | # diagonalize the lzcplx matrix 156 | w, v = np.linalg.eig(lzcplx) 157 | 158 | wij2 = np.multiply(np.abs(v), np.abs(v)) 159 | #x, y = np.where(wij2 > tolv) 160 | idxs = [np.nonzero(row > tolv)[0] for row in wij2] 161 | for row, comp in enumerate(idxs): 162 | out.append([(IG, w.real[m], wij2[row, m]*100.0) for m in comp]) 163 | 164 | evs = [np.unique(np.round(np.abs(np.array([x[1] for x in row])), decimals=1)) for row in out] 165 | lzvals = [int(x[0]) if x.size == 1 else np.NaN for x in evs] 166 | 167 | self['lzvals'] = [int(x[0]) if x.size == 1 else np.NaN for x in evs] 168 | self['lzlabels'] = self['lzvals'].map(lzmap) 169 | return out 170 | 171 | def lzmos(self, ETOLLZ=1.0e-6, TOLV=1.0e-2): 172 | ''' 173 | A python rewrite of the GAMESS(US) LZMOS subroutine (from symorb.src) for analyzing the Lz composition of the 174 | orbtials 175 | 176 | Args: 177 | ETOLLZ : float 178 | TOLV : float 179 | 180 | ''' 181 | 182 | lzmap = {0: 'sigma', 1: 'pi', 2: 'delta', 3: 'phi'} 183 | 184 | df = DictionaryFile(self.dictfile) 185 | # read Lz integrals from the dictionary file 186 | lzvec = df.read_record(379) 187 | # expand triangular to square matrix 188 | lzints = tri2full(lzvec, sym=False) 189 | 190 | mos = self.coeffs.values 191 | ev = self.eigenvals.values 192 | out = [] 193 | 194 | L = 0 195 | ILAST = 0 196 | IG = 0 197 | N = 1 198 | for I in range(1, self.nmo + 1): 199 | EI = 0 200 | if I < self.nmo: EI = ev[I] 201 | 202 | if (abs(ev[I - 1] - EI) > ETOLLZ or I > self.nmo): 203 | 204 | IG += 1 205 | # transform the integrals to the MO basis 206 | lzmo = np.dot(mos[:, ILAST:ILAST+N].T, np.dot(lzints, mos[:, ILAST:ILAST+N])) 207 | # tranform to complex type 208 | lzcplx = np.zeros_like(lzmo, dtype=np.complex128) 209 | lzcplx.imag = -lzmo 210 | 211 | # diagonalize the lzcplx matrix 212 | w, v = np.linalg.eig(lzcplx) 213 | 214 | for j in range(v.shape[0]): 215 | m = -1 216 | temp = [] 217 | for k in range(v.shape[1]): 218 | wij = np.abs(v[j, k]) 219 | if wij*wij > TOLV: 220 | m += 1 221 | temp.append(wij*wij*100.0) 222 | out.append([(IG, w.real[mi], temp[mi]) for mi in range(m+1)]) 223 | 224 | ILAST = I 225 | N = 1 226 | else: 227 | N = N + 1 228 | 229 | # should check here if the length of the evs is the same as the number of rows of the dataframe 230 | # if somethings wrong probably the ETOLLZ should be adjusted 231 | evs = [np.unique(np.round(np.abs(np.array([x[1] for x in row])), decimals=1)) for row in out] 232 | lzvals = [int(x[0]) if x.size == 1 else np.NaN for x in evs] 233 | 234 | self['lzvals'] = [int(x[0]) if x.size == 1 else np.NaN for x in evs] 235 | self['lzlabels'] = self['lzvals'].map(lzmap) 236 | self['ig'] = [x[0][0] for x in out] 237 | return None 238 | 239 | def fragment_populations(self): 240 | ''' 241 | Calculate the fragment populations and assign each orbital to a fragment 242 | ''' 243 | 244 | glp = GamessLogParser(self.logfile) 245 | self.aoinfo = pd.DataFrame(data=glp.get_ao_labels(orbs=self.name + ' orbs')) 246 | 247 | idx1 = self.aoinfo.loc[self.aoinfo['center'] == 1, 'index'].values 248 | self['center 1 pop'] = (self.coeffs.loc[idx1, :]**2).sum() 249 | idx2 = self.aoinfo.loc[self.aoinfo['center'] == 2, 'index'].values 250 | self['center 2 pop'] = (self.coeffs.loc[idx2, :]**2).sum() 251 | 252 | self['fragment'] = np.where(self['center 1 pop'] > self['center 2 pop'], 1, 2) 253 | 254 | def check_duplicates(a, decimals=6): 255 | ''' 256 | This funciton assumes that the array `a` is sorted 257 | 258 | http://stackoverflow.com/questions/25264798/checking-for-and-indexing-non-unique-duplicate-values-in-a-numpy-array 259 | http://stackoverflow.com/questions/5426908/find-unique-elements-of-floating-point-array-in-numpy-with-comparison-using-a-d 260 | ''' 261 | 262 | unq, unq_idx, unq_cnt = np.unique(np.round(a, decimals=decimals), return_inverse=True, return_counts=True) 263 | 264 | indices = np.zeros((len(unq), 2), dtype=np.int) 265 | for ig in range(len(unq)): 266 | idx = np.nonzero(unq_idx == ig)[0] 267 | indices[ig, :] = [np.min(idx), np.max(idx) + 1] 268 | 269 | return unq, indices 270 | --------------------------------------------------------------------------------