Skip to content

Commit 265c016

Browse files
jarrodmccdamiansteiger
authored andcommitted
Update data format (#4)
1 parent fbd9930 commit 265c016

File tree

5 files changed

+135
-42
lines changed

5 files changed

+135
-42
lines changed

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/psi4_demo.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
"language_info": {
192192
"codemirror_mode": {
193193
"name": "ipython",
194-
"version": 2
194+
"version": 2.0
195195
},
196196
"file_extension": ".py",
197197
"mimetype": "text/x-python",
@@ -202,5 +202,5 @@
202202
}
203203
},
204204
"nbformat": 4,
205-
"nbformat_minor": 2
206-
}
205+
"nbformat_minor": 0
206+
}

fermilibpluginpsi4/_psi4_conversion_functions.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,49 +209,49 @@ def beta_unoccupied(i):
209209
# Store singles
210210
for entry in T1IA_Amps:
211211
i, a, value = entry
212-
single_amplitudes[alpha_occupied(i),
213-
alpha_unoccupied(a)] = value
212+
single_amplitudes[alpha_unoccupied(a),
213+
alpha_occupied(i)] = value
214214
if (restricted):
215-
single_amplitudes[beta_occupied(i),
216-
beta_unoccupied(a)] = value
215+
single_amplitudes[beta_unoccupied(a),
216+
beta_occupied(i)] = value
217217

218218
for entry in T1ia_Amps:
219219
i, a, value = entry
220-
single_amplitudes[beta_occupied(i),
221-
beta_unoccupied(a)] = value
220+
single_amplitudes[beta_unoccupied(a),
221+
beta_occupied(i)] = value
222222

223223
# Store doubles, include factor of 1/2 for convention
224224
for entry in T2IJAB_Amps:
225225
i, j, a, b, value = entry
226-
double_amplitudes[alpha_occupied(i),
227-
alpha_unoccupied(a),
228-
alpha_occupied(j),
229-
alpha_unoccupied(b)] = -value / 2.
226+
double_amplitudes[alpha_unoccupied(a),
227+
alpha_occupied(i),
228+
alpha_unoccupied(b),
229+
alpha_occupied(j)] = value / 2.
230230
if (restricted):
231-
double_amplitudes[beta_occupied(i),
232-
beta_unoccupied(a),
233-
beta_occupied(j),
234-
beta_unoccupied(b)] = -value / 2.
231+
double_amplitudes[beta_unoccupied(a),
232+
beta_occupied(i),
233+
beta_unoccupied(b),
234+
beta_occupied(j)] = value / 2.
235235

236236
for entry in T2ijab_Amps:
237237
i, j, a, b, value = entry
238-
double_amplitudes[beta_occupied(i),
239-
beta_unoccupied(a),
240-
beta_occupied(j),
241-
beta_unoccupied(b)] = -value / 2.
238+
double_amplitudes[beta_unoccupied(a),
239+
beta_occupied(i),
240+
beta_unoccupied(b),
241+
beta_occupied(j)] = value / 2.
242242

243243
for entry in T2IjAb_Amps:
244244
i, j, a, b, value = entry
245-
double_amplitudes[alpha_occupied(i),
246-
alpha_unoccupied(a),
247-
beta_occupied(j),
248-
beta_unoccupied(b)] = -value / 2.
245+
double_amplitudes[alpha_unoccupied(a),
246+
alpha_occupied(i),
247+
beta_unoccupied(b),
248+
beta_occupied(j)] = value / 2.
249249

250250
if (restricted):
251-
double_amplitudes[beta_occupied(i),
252-
beta_unoccupied(a),
253-
alpha_occupied(j),
254-
alpha_unoccupied(b)] = -value / 2.
251+
double_amplitudes[beta_unoccupied(a),
252+
beta_occupied(i),
253+
alpha_unoccupied(b),
254+
alpha_occupied(j)] = value / 2.
255255

256256
# Package into InteractionOperator.
257257
molecule = InteractionOperator(0.0,

fermilibpluginpsi4/_psi4_template

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from fermilib.config import *
66
from fermilib.ops._interaction_tensor import (one_body_basis_change,
77
two_body_basis_change)
88
from fermilib.utils import MolecularData
9+
from numpy import array
910

1011
sys.path.append('&THIS_DIRECTORY')
1112
from _psi4_conversion_functions import *
@@ -22,7 +23,8 @@ molecule = MolecularData(&geometry,
2223
'&basis',
2324
&multiplicity,
2425
&charge,
25-
_description)
26+
_description,
27+
filename='&mol_filename')
2628

2729
# Set molecular geometry and symmetry.
2830
molecule mol {
@@ -45,11 +47,11 @@ set globals {
4547
basis &basis
4648
freeze_core false
4749
fail_on_maxiter true
48-
df_scf_guess true
50+
df_scf_guess false
4951
opdm true
5052
tpdm true
5153
soscf false
52-
scf_type df
54+
scf_type pk
5355
maxiter 1e6
5456
num_amps_print 1e6
5557
r_convergence 1e-6
@@ -93,8 +95,7 @@ if &run_scf:
9395
two_body_integrals = numpy.einsum('psqr', two_body_integrals)
9496
two_body_integrals = two_body_basis_change(
9597
two_body_integrals, molecule.canonical_orbitals)
96-
integrals_name = molecule.filename + '_eri'
97-
numpy.save(integrals_name, two_body_integrals)
98+
molecule.two_body_integrals = two_body_integrals
9899
molecule.save()
99100

100101

@@ -157,8 +158,7 @@ if &run_cisd:
157158

158159
# Store 1-RDM in molecule file, 2-RDM separately in other file.
159160
molecule.cisd_one_rdm = cisd_one_rdm
160-
cisd_rdm_name = molecule.filename + '_cisd_rdm'
161-
numpy.save(cisd_rdm_name, cisd_two_rdm)
161+
molecule.cisd_two_rdm = cisd_two_rdm
162162
molecule.save()
163163

164164

@@ -203,8 +203,7 @@ if &run_fci:
203203

204204
# Store 1-RDM in molecule file, 2-RDM separately in other file.
205205
molecule.fci_one_rdm = fci_one_rdm
206-
fci_rdm_name = molecule.filename + '_fci_rdm'
207-
numpy.save(fci_rdm_name, fci_two_rdm)
206+
molecule.fci_two_rdm = fci_two_rdm
208207
molecule.save()
209208

210209

fermilibpluginpsi4/_run_psi4.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def generate_psi4_input(molecule,
5757
run_fci,
5858
verbose,
5959
tolerate_error,
60-
memory):
60+
memory,
61+
template_file):
6162
"""This function creates and saves a psi4 input file.
6263
6364
Args:
@@ -70,6 +71,7 @@ def generate_psi4_input(molecule,
7071
verbose: Boolean whether to print calculation results to screen.
7172
tolerate_error: Whether to fail or merely warn when Psi4 fails.
7273
memory: Int giving amount of memory to allocate in MB.
74+
template_file(str): Specify the filename of a Psi4 template
7375
7476
Returns:
7577
input_file: A string giving the name of the saved input file.
@@ -81,7 +83,8 @@ def generate_psi4_input(molecule,
8183
psi4_directory = os.path.dirname(os.path.realpath(__file__))
8284

8385
# Parse input template.
84-
template_file = psi4_directory + '/_psi4_template'
86+
if template_file is None:
87+
template_file = psi4_directory + '/_psi4_template'
8588
input_template = []
8689
with open(template_file, 'r') as stream:
8790
for line in stream:
@@ -103,6 +106,8 @@ def generate_psi4_input(molecule,
103106
for line in input_content]
104107
input_content = [re.sub('&description', str(molecule.description), line)
105108
for line in input_content]
109+
input_content = [re.sub('&mol_filename', str(molecule.filename), line)
110+
for line in input_content]
106111
input_content = [re.sub('&geo_string', geo_string, line)
107112
for line in input_content]
108113

@@ -158,7 +163,8 @@ def run_psi4(molecule,
158163
tolerate_error=False,
159164
delete_input=True,
160165
delete_output=False,
161-
memory=8000):
166+
memory=8000,
167+
template_file=None):
162168
"""This function runs a Psi4 calculation.
163169
164170
Args:
@@ -173,6 +179,7 @@ def run_psi4(molecule,
173179
delete_input: Optional boolean to delete psi4 input file.
174180
delete_output: Optional boolean to delete psi4 output file.
175181
memory: Optional int giving amount of memory to allocate in MB.
182+
template_file(str): Path to Psi4 template file
176183
177184
Returns:
178185
molecule: The updated MolecularData object.
@@ -189,7 +196,8 @@ def run_psi4(molecule,
189196
run_fci,
190197
verbose,
191198
tolerate_error,
192-
memory)
199+
memory,
200+
template_file)
193201

194202
# Run psi4.
195203
output_file = molecule.filename + '.out'

0 commit comments

Comments
 (0)