Skip to content

Commit f79900c

Browse files
Merge pull request #5 from ProjectQ-Framework/develop
First pre-release
2 parents 75ae1eb + 19f7532 commit f79900c

10 files changed

+1286
-0
lines changed

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FermiLib Plugin to interface with PySCF
2+
=======================================
3+
4+
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 `PySCF <https://github.com/sunqm/pyscf>`__ (licensed under BSD-2-Clause).
5+
6+
License
7+
-------
8+
9+
This plugin is released under the Apache 2 license.

examples/generate_data.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
"""This is a simple script for generating data."""
14+
import os
15+
16+
from fermilib.utils import (make_atomic_ring,
17+
make_atom,
18+
periodic_table)
19+
20+
from fermilibpluginpyscf import run_pyscf
21+
22+
23+
if __name__ == '__main__':
24+
25+
# Set chemical parameters.
26+
basis = 'sto-3g'
27+
max_electrons = 10
28+
spacing = 0.7414
29+
compute_elements = 0
30+
31+
# Select calculations.
32+
force_recompute = 1
33+
run_scf = 1
34+
run_mp2 = 1
35+
run_cisd = 1
36+
run_ccsd = 1
37+
run_fci = 1
38+
verbose = 1
39+
40+
# Generate data.
41+
for n_electrons in range(2, max_electrons + 1):
42+
43+
# Initialize.
44+
if compute_elements:
45+
atomic_symbol = periodic_table[n_electrons]
46+
molecule = make_atom(atomic_symbol, basis)
47+
else:
48+
molecule = make_atomic_ring(n_electrons, spacing, basis)
49+
if os.path.exists(molecule.filename + '.hdf5'):
50+
molecule.load()
51+
52+
# To run or not to run.
53+
if run_scf and not molecule.hf_energy:
54+
run_job = 1
55+
elif run_mp2 and not molecule.mp2_energy:
56+
run_job = 1
57+
elif run_cisd and not molecule.cisd_energy:
58+
run_job = 1
59+
elif run_ccsd and not molecule.ccsd_energy:
60+
run_job = 1
61+
elif run_fci and not molecule.fci_energy:
62+
run_job = 1
63+
else:
64+
run_job = force_recompute
65+
66+
# Run.
67+
if run_job:
68+
molecule = run_pyscf(molecule,
69+
run_scf=run_scf,
70+
run_mp2=run_mp2,
71+
run_cisd=run_cisd,
72+
run_ccsd=run_ccsd,
73+
run_fci=run_fci,
74+
verbose=verbose)
75+
molecule.save()

examples/generate_diatomic.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
"""This is a simple script for generating data."""
14+
import os
15+
16+
from fermilib.utils import MolecularData
17+
18+
from fermilibpluginpyscf import run_pyscf
19+
20+
21+
if __name__ == '__main__':
22+
23+
# Set chemical parameters.
24+
element_names = ['H', 'H']
25+
basis = 'sto-3g'
26+
charge = 0
27+
multiplicity = 1
28+
29+
# Single point at equilibrium for testing
30+
spacings = [0.7414]
31+
32+
# Add points for a full dissociation curve from 0.1 to 3.0 angstroms
33+
spacings += [0.1 * r for r in range(1, 31)]
34+
35+
# Set run options
36+
run_scf = 1
37+
run_mp2 = 1
38+
run_cisd = 1
39+
run_ccsd = 1
40+
run_fci = 1
41+
verbose = 1
42+
43+
# Run Diatomic Curve
44+
for spacing in spacings:
45+
description = "{}".format(spacing)
46+
geometry = [[element_names[0], [0, 0, 0]],
47+
[element_names[1], [0, 0, spacing]]]
48+
molecule = MolecularData(geometry,
49+
basis,
50+
multiplicity,
51+
charge,
52+
description)
53+
54+
molecule = run_pyscf(molecule,
55+
run_scf=run_scf,
56+
run_mp2=run_mp2,
57+
run_cisd=run_cisd,
58+
run_ccsd=run_ccsd,
59+
run_fci=run_fci,
60+
verbose=verbose)
61+
molecule.save()
62+
63+
# Run Li H single point
64+
description = "1.45"
65+
geometry = [['Li', [0, 0, 0]],
66+
['H', [0, 0, 1.45]]]
67+
molecule = MolecularData(geometry,
68+
basis,
69+
multiplicity,
70+
charge,
71+
description)
72+
73+
molecule = run_pyscf(molecule,
74+
run_scf=run_scf,
75+
run_mp2=run_mp2,
76+
run_cisd=run_cisd,
77+
run_ccsd=run_ccsd,
78+
run_fci=run_fci,
79+
verbose=verbose)
80+
molecule.save()

examples/plotter.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
"""These functions compare properties of different molecules."""
14+
import matplotlib.pyplot
15+
import numpy
16+
import warnings
17+
18+
from fermilib.utils import (make_atom, make_atomic_ring,
19+
MolecularData, periodic_table)
20+
21+
22+
def latex_name(molecule):
23+
"""Write the name of the molecule in LaTeX.
24+
25+
Returns:
26+
name: A string giving the name in LaTeX.
27+
"""
28+
# Get sorted atom vector.
29+
atoms = [item[0] for item in molecule.geometry]
30+
atom_charge_info = [(atom, atoms.count(atom)) for atom in set(atoms)]
31+
sorted_info = sorted(atom_charge_info,
32+
key=lambda atom: molecular_data.
33+
_PERIODIC_HASH_TABLE[atom[0]])
34+
35+
# Name molecule and return.
36+
name = '{}$_{}$'.format(sorted_info[0][0], sorted_info[0][1])
37+
for info in sorted_info[1::]:
38+
name += '{}$_{}$'.format(info[0], info[1])
39+
return name
40+
41+
42+
# Run.
43+
if __name__ == '__main__':
44+
45+
# Set plot parameters.
46+
matplotlib.pyplot.rcParams['text.usetex'] = True
47+
matplotlib.pyplot.rcParams['text.latex.unicode'] = True
48+
matplotlib.pyplot.rc('text', usetex=True)
49+
matplotlib.pyplot.rc('font', family='sans=serif')
50+
marker_size = 6
51+
line_width = 2
52+
axis_size = 12
53+
font_size = 16
54+
x_log = 0
55+
y_log = 0
56+
57+
# Set chemical series parameters.
58+
plot_elements = 0
59+
max_electrons = 10
60+
spacing = 0.7414
61+
basis = 'sto-3g'
62+
63+
# Get chemical series.
64+
molecular_series = []
65+
for n_electrons in range(2, max_electrons + 1):
66+
if plot_elements:
67+
atomic_symbol = periodic_table[n_electrons]
68+
molecule = make_atom(atomic_symbol, basis)
69+
else:
70+
molecule = make_atomic_ring(n_electrons, spacing, basis)
71+
molecule.load()
72+
molecular_series += [molecule]
73+
74+
# Get plot data.
75+
x_values = []
76+
y_values = []
77+
for molecule in molecular_series:
78+
79+
# x-axis.
80+
x_label = 'Number of Electrons'
81+
x_values += [molecule.n_electrons]
82+
83+
# y-axis.
84+
y_label = 'MP2 Energy'
85+
y_values += [molecule.mp2_energy]
86+
87+
# Print.
88+
print('\n{} for {} = {}.'.format(x_label, molecule.name, x_values[-1]))
89+
print('{} for {} = {}.'.format(y_label, molecule.name, y_values[-1]))
90+
91+
# Plot.
92+
matplotlib.pyplot.figure(0)
93+
matplotlib.pyplot.plot(x_values, y_values, lw=0, marker='o')
94+
95+
# Set log scales.
96+
if y_log:
97+
matplotlib.pyplot.yscale('log')
98+
if x_log:
99+
matplotlib.pyplot.xscale('log')
100+
101+
# Finish making the plot.
102+
matplotlib.pyplot.xticks(size=axis_size)
103+
matplotlib.pyplot.yticks(size=axis_size)
104+
matplotlib.pyplot.xlabel(r'%s' % x_label, fontsize=font_size)
105+
matplotlib.pyplot.ylabel(r'%s' % y_label, fontsize=font_size)
106+
matplotlib.pyplot.show()

0 commit comments

Comments
 (0)