Skip to content

Commit 5f7e94a

Browse files
Release v0.1a1
2 parents 99c9895 + 1b90ff3 commit 5f7e94a

File tree

11 files changed

+433
-135
lines changed

11 files changed

+433
-135
lines changed

README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ FermiLib plugin to interface with Psi4
33

44
This repository contains a plugin which allows `FermiLib <http://github.com/ProjectQ-Framework/FermiLib>`__ (licensed under Apache 2) to interface with the open-source quantum chemistry package `Psi4 <http://www.psicode.org>`__ (licensed under GNU Lesser General Public License version 3).
55

6+
Installation
7+
------------
8+
9+
To install this plugin, clone this git repo and then change directory to the top level folder. Then, run
10+
11+
.. code-block:: bash
12+
13+
python -m pip install -e .
14+
15+
Alternatively, one can install using pip with the command
16+
17+
.. code-block:: bash
18+
19+
python -m pip install fermilibpluginpsi4
20+
621
License
722
-------
823
Copyright (C) 2017 FermiLib Developers

examples/generate_data.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# FermiLib plugin to interface with Psi4
2+
# Copyright (C) 2017 FermiLib Developers
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
"""This is a simple script for generating data."""
18+
import os
19+
20+
from fermilib.utils import (make_atomic_ring,
21+
make_atom,
22+
MolecularData,
23+
periodic_table)
24+
25+
from fermilibpluginpsi4 import run_psi4
26+
27+
28+
if __name__ == '__main__':
29+
30+
# Set chemical parameters.
31+
basis = 'sto-3g'
32+
max_electrons = 10
33+
spacing = 0.7414
34+
compute_elements = 0
35+
36+
# Select calculations.
37+
force_recompute = 1
38+
run_scf = 1
39+
run_mp2 = 1
40+
run_cisd = 1
41+
run_ccsd = 1
42+
run_fci = 1
43+
verbose = 1
44+
tolerate_error = 1
45+
46+
# Generate data.
47+
for n_electrons in range(2, max_electrons + 1):
48+
49+
# Initialize.
50+
if compute_elements:
51+
atomic_symbol = periodic_table[n_electrons]
52+
molecule = make_atom(atomic_symbol, basis)
53+
else:
54+
molecule = make_atomic_ring(n_electrons, spacing, basis)
55+
if os.path.exists(molecule.filename + '.hdf5'):
56+
molecule.load()
57+
58+
# To run or not to run.
59+
if run_scf and not molecule.hf_energy:
60+
run_job = 1
61+
elif run_mp2 and not molecule.mp2_energy:
62+
run_job = 1
63+
elif run_cisd and not molecule.cisd_energy:
64+
run_job = 1
65+
elif run_ccsd and not molecule.ccsd_energy:
66+
run_job = 1
67+
elif run_fci and not molecule.fci_energy:
68+
run_job = 1
69+
else:
70+
run_job = force_recompute
71+
72+
# Run.
73+
if run_job:
74+
molecule = run_psi4(molecule,
75+
run_scf=run_scf,
76+
run_mp2=run_mp2,
77+
run_cisd=run_cisd,
78+
run_ccsd=run_ccsd,
79+
run_fci=run_fci,
80+
verbose=verbose,
81+
tolerate_error=tolerate_error)
82+
molecule.save()

examples/generate_diatomic.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# FermiLib plugin to interface with Psi4
2+
# Copyright (C) 2017 FermiLib Developers
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
"""This is a simple script for generating data."""
18+
import os
19+
20+
from fermilib.utils import MolecularData
21+
22+
from fermilibpluginpsi4 import run_psi4
23+
24+
if __name__ == '__main__':
25+
26+
# Set chemical parameters.
27+
element_names = ['H', 'H']
28+
basis = 'sto-3g'
29+
charge = 0
30+
multiplicity = 1
31+
32+
# Single point at equilibrium for testing
33+
spacings = [0.7414]
34+
35+
# Add points for a full dissociation curve from 0.1 to 3.0 angstroms
36+
spacings += [0.1 * r for r in range(1, 31)]
37+
38+
# Set run options
39+
run_scf = 1
40+
run_mp2 = 1
41+
run_cisd = 1
42+
run_ccsd = 1
43+
run_fci = 1
44+
verbose = 1
45+
tolerate_error = 1
46+
47+
# Run Diatomic Curve
48+
for spacing in spacings:
49+
description = "{}".format(spacing)
50+
geometry = [[element_names[0], [0, 0, 0]],
51+
[element_names[1], [0, 0, spacing]]]
52+
molecule = MolecularData(geometry,
53+
basis,
54+
multiplicity,
55+
charge,
56+
description)
57+
58+
molecule = run_psi4(molecule,
59+
run_scf=run_scf,
60+
run_mp2=run_mp2,
61+
run_cisd=run_cisd,
62+
run_ccsd=run_ccsd,
63+
run_fci=run_fci,
64+
verbose=verbose,
65+
tolerate_error=tolerate_error)
66+
molecule.save()
67+
68+
# Run Li H single point
69+
description = "1.45"
70+
geometry = [['Li', [0, 0, 0]],
71+
['H', [0, 0, 1.45]]]
72+
molecule = MolecularData(geometry,
73+
basis,
74+
multiplicity,
75+
charge,
76+
description)
77+
78+
molecule = run_psi4(molecule,
79+
run_scf=run_scf,
80+
run_mp2=run_mp2,
81+
run_cisd=run_cisd,
82+
run_ccsd=run_ccsd,
83+
run_fci=run_fci,
84+
verbose=verbose,
85+
tolerate_error=tolerate_error)
86+
molecule.save()

examples/plotter.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# FermiLib plugin to interface with Psi4
2+
# Copyright (C) 2017 FermiLib Developers
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
"""These functions compare properties of different molecules."""
18+
import numpy
19+
import warnings
20+
21+
from fermilib.utils import (make_atom, make_atomic_ring,
22+
MolecularData, periodic_table)
23+
24+
with warnings.catch_warnings():
25+
warnings.simplefilter('ignore')
26+
import pylab
27+
28+
29+
def latex_name(molecule):
30+
"""Write the name of the molecule in LaTeX.
31+
32+
Returns:
33+
name: A string giving the name in LaTeX.
34+
"""
35+
# Get sorted atom vector.
36+
atoms = [item[0] for item in molecule.geometry]
37+
atom_charge_info = [(atom, atoms.count(atom)) for atom in set(atoms)]
38+
sorted_info = sorted(atom_charge_info,
39+
key=lambda atom: molecular_data.
40+
_PERIODIC_HASH_TABLE[atom[0]])
41+
42+
# Name molecule and return.
43+
name = '{}$_{}$'.format(sorted_info[0][0], sorted_info[0][1])
44+
for info in sorted_info[1::]:
45+
name += '{}$_{}$'.format(info[0], info[1])
46+
return name
47+
48+
49+
# Run.
50+
if __name__ == '__main__':
51+
52+
# Set plot parameters.
53+
pylab.rcParams['text.usetex'] = True
54+
pylab.rcParams['text.latex.unicode'] = True
55+
pylab.rc('text', usetex=True)
56+
pylab.rc('font', family='sans=serif')
57+
marker_size = 6
58+
line_width = 2
59+
axis_size = 12
60+
font_size = 16
61+
x_log = 0
62+
y_log = 0
63+
64+
# Set chemical series parameters.
65+
plot_elements = 0
66+
max_electrons = 10
67+
spacing = 0.7414
68+
basis = 'sto-3g'
69+
70+
# Get chemical series.
71+
molecular_series = []
72+
for n_electrons in range(2, max_electrons + 1):
73+
if plot_elements:
74+
atomic_symbol = periodic_table[n_electrons]
75+
molecule = make_atom(atomic_symbol, basis)
76+
else:
77+
molecule = make_atomic_ring(n_electrons, spacing, basis)
78+
molecule.load()
79+
molecular_series += [molecule]
80+
81+
# Get plot data.
82+
x_values = []
83+
y_values = []
84+
for molecule in molecular_series:
85+
86+
# x-axis.
87+
x_label = 'Number of Electrons'
88+
x_values += [molecule.n_electrons]
89+
90+
# y-axis.
91+
y_label = 'MP2 Energy'
92+
y_values += [molecule.mp2_energy]
93+
94+
# Print.
95+
print('\n{} for {} = {}.'.format(x_label, molecule.name, x_values[-1]))
96+
print('{} for {} = {}.'.format(y_label, molecule.name, y_values[-1]))
97+
98+
# Plot.
99+
pylab.figure(0)
100+
pylab.plot(x_values, y_values, lw=0, marker='o')
101+
102+
# Set log scales.
103+
if y_log:
104+
pylab.yscale('log')
105+
if x_log:
106+
pylab.xscale('log')
107+
108+
# Finish making the plot.
109+
pylab.xticks(size=axis_size)
110+
pylab.yticks(size=axis_size)
111+
pylab.xlabel(r'%s' % x_label, fontsize=font_size)
112+
pylab.ylabel(r'%s' % y_label, fontsize=font_size)
113+
pylab.show()

0 commit comments

Comments
 (0)