Skip to content

Commit

Permalink
Merge pull request #5 from ProjectQ-Framework/develop
Browse files Browse the repository at this point in the history
First pre-release
  • Loading branch information
damiansteiger authored Jul 6, 2017
2 parents 75ae1eb + 19f7532 commit f79900c
Show file tree
Hide file tree
Showing 10 changed files with 1,286 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FermiLib Plugin to interface with PySCF
=======================================

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

License
-------

This plugin is released under the Apache 2 license.
75 changes: 75 additions & 0 deletions examples/generate_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This is a simple script for generating data."""
import os

from fermilib.utils import (make_atomic_ring,
make_atom,
periodic_table)

from fermilibpluginpyscf import run_pyscf


if __name__ == '__main__':

# Set chemical parameters.
basis = 'sto-3g'
max_electrons = 10
spacing = 0.7414
compute_elements = 0

# Select calculations.
force_recompute = 1
run_scf = 1
run_mp2 = 1
run_cisd = 1
run_ccsd = 1
run_fci = 1
verbose = 1

# Generate data.
for n_electrons in range(2, max_electrons + 1):

# Initialize.
if compute_elements:
atomic_symbol = periodic_table[n_electrons]
molecule = make_atom(atomic_symbol, basis)
else:
molecule = make_atomic_ring(n_electrons, spacing, basis)
if os.path.exists(molecule.filename + '.hdf5'):
molecule.load()

# To run or not to run.
if run_scf and not molecule.hf_energy:
run_job = 1
elif run_mp2 and not molecule.mp2_energy:
run_job = 1
elif run_cisd and not molecule.cisd_energy:
run_job = 1
elif run_ccsd and not molecule.ccsd_energy:
run_job = 1
elif run_fci and not molecule.fci_energy:
run_job = 1
else:
run_job = force_recompute

# Run.
if run_job:
molecule = run_pyscf(molecule,
run_scf=run_scf,
run_mp2=run_mp2,
run_cisd=run_cisd,
run_ccsd=run_ccsd,
run_fci=run_fci,
verbose=verbose)
molecule.save()
80 changes: 80 additions & 0 deletions examples/generate_diatomic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This is a simple script for generating data."""
import os

from fermilib.utils import MolecularData

from fermilibpluginpyscf import run_pyscf


if __name__ == '__main__':

# Set chemical parameters.
element_names = ['H', 'H']
basis = 'sto-3g'
charge = 0
multiplicity = 1

# Single point at equilibrium for testing
spacings = [0.7414]

# Add points for a full dissociation curve from 0.1 to 3.0 angstroms
spacings += [0.1 * r for r in range(1, 31)]

# Set run options
run_scf = 1
run_mp2 = 1
run_cisd = 1
run_ccsd = 1
run_fci = 1
verbose = 1

# Run Diatomic Curve
for spacing in spacings:
description = "{}".format(spacing)
geometry = [[element_names[0], [0, 0, 0]],
[element_names[1], [0, 0, spacing]]]
molecule = MolecularData(geometry,
basis,
multiplicity,
charge,
description)

molecule = run_pyscf(molecule,
run_scf=run_scf,
run_mp2=run_mp2,
run_cisd=run_cisd,
run_ccsd=run_ccsd,
run_fci=run_fci,
verbose=verbose)
molecule.save()

# Run Li H single point
description = "1.45"
geometry = [['Li', [0, 0, 0]],
['H', [0, 0, 1.45]]]
molecule = MolecularData(geometry,
basis,
multiplicity,
charge,
description)

molecule = run_pyscf(molecule,
run_scf=run_scf,
run_mp2=run_mp2,
run_cisd=run_cisd,
run_ccsd=run_ccsd,
run_fci=run_fci,
verbose=verbose)
molecule.save()
106 changes: 106 additions & 0 deletions examples/plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""These functions compare properties of different molecules."""
import matplotlib.pyplot
import numpy
import warnings

from fermilib.utils import (make_atom, make_atomic_ring,
MolecularData, periodic_table)


def latex_name(molecule):
"""Write the name of the molecule in LaTeX.
Returns:
name: A string giving the name in LaTeX.
"""
# Get sorted atom vector.
atoms = [item[0] for item in molecule.geometry]
atom_charge_info = [(atom, atoms.count(atom)) for atom in set(atoms)]
sorted_info = sorted(atom_charge_info,
key=lambda atom: molecular_data.
_PERIODIC_HASH_TABLE[atom[0]])

# Name molecule and return.
name = '{}$_{}$'.format(sorted_info[0][0], sorted_info[0][1])
for info in sorted_info[1::]:
name += '{}$_{}$'.format(info[0], info[1])
return name


# Run.
if __name__ == '__main__':

# Set plot parameters.
matplotlib.pyplot.rcParams['text.usetex'] = True
matplotlib.pyplot.rcParams['text.latex.unicode'] = True
matplotlib.pyplot.rc('text', usetex=True)
matplotlib.pyplot.rc('font', family='sans=serif')
marker_size = 6
line_width = 2
axis_size = 12
font_size = 16
x_log = 0
y_log = 0

# Set chemical series parameters.
plot_elements = 0
max_electrons = 10
spacing = 0.7414
basis = 'sto-3g'

# Get chemical series.
molecular_series = []
for n_electrons in range(2, max_electrons + 1):
if plot_elements:
atomic_symbol = periodic_table[n_electrons]
molecule = make_atom(atomic_symbol, basis)
else:
molecule = make_atomic_ring(n_electrons, spacing, basis)
molecule.load()
molecular_series += [molecule]

# Get plot data.
x_values = []
y_values = []
for molecule in molecular_series:

# x-axis.
x_label = 'Number of Electrons'
x_values += [molecule.n_electrons]

# y-axis.
y_label = 'MP2 Energy'
y_values += [molecule.mp2_energy]

# Print.
print('\n{} for {} = {}.'.format(x_label, molecule.name, x_values[-1]))
print('{} for {} = {}.'.format(y_label, molecule.name, y_values[-1]))

# Plot.
matplotlib.pyplot.figure(0)
matplotlib.pyplot.plot(x_values, y_values, lw=0, marker='o')

# Set log scales.
if y_log:
matplotlib.pyplot.yscale('log')
if x_log:
matplotlib.pyplot.xscale('log')

# Finish making the plot.
matplotlib.pyplot.xticks(size=axis_size)
matplotlib.pyplot.yticks(size=axis_size)
matplotlib.pyplot.xlabel(r'%s' % x_label, fontsize=font_size)
matplotlib.pyplot.ylabel(r'%s' % y_label, fontsize=font_size)
matplotlib.pyplot.show()
Loading

0 comments on commit f79900c

Please sign in to comment.