|
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 openfermion.chem 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 | | - max_electrons = 10 |
59 | | - spacing = 0.7414 |
60 | | - basis = 'sto-3g' |
61 | | - |
62 | | - # Get chemical series. |
63 | | - molecular_series = [] |
64 | | - for n_electrons in range(2, max_electrons + 1): |
65 | | - molecule = make_atomic_ring(n_electrons, spacing, basis) |
66 | | - molecule.load() |
67 | | - molecular_series += [molecule] |
68 | | - |
69 | | - # Get plot data. |
70 | | - x_values = [] |
71 | | - y_values = [] |
72 | | - for molecule in molecular_series: |
73 | | - |
74 | | - # x-axis. |
75 | | - x_label = 'Number of Electrons' |
76 | | - x_values += [molecule.n_electrons] |
77 | | - |
78 | | - # y-axis. |
79 | | - y_label = 'MP2 Energy' |
80 | | - y_values += [molecule.mp2_energy] |
81 | | - |
82 | | - # Print. |
83 | | - print('\n{} for {} = {}.'.format(x_label, molecule.name, x_values[-1])) |
84 | | - print('{} for {} = {}.'.format(y_label, molecule.name, y_values[-1])) |
85 | | - |
86 | | - # Plot. |
87 | | - matplotlib.pyplot.figure(0) |
88 | | - matplotlib.pyplot.plot(x_values, y_values, lw=0, marker='o') |
89 | | - |
90 | | - # Set log scales. |
91 | | - if y_log: |
92 | | - matplotlib.pyplot.yscale('log') |
93 | | - if x_log: |
94 | | - matplotlib.pyplot.xscale('log') |
95 | | - |
96 | | - # Finish making the plot. |
97 | | - matplotlib.pyplot.xticks(size=axis_size) |
98 | | - matplotlib.pyplot.yticks(size=axis_size) |
99 | | - matplotlib.pyplot.xlabel(r'%s' % x_label, fontsize=font_size) |
100 | | - matplotlib.pyplot.ylabel(r'%s' % y_label, fontsize=font_size) |
101 | | - matplotlib.pyplot.show() |
| 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 openfermion.chem 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 | + max_electrons = 10 |
| 59 | + spacing = 0.7414 |
| 60 | + basis = 'sto-3g' |
| 61 | + |
| 62 | + # Get chemical series. |
| 63 | + molecular_series = [] |
| 64 | + for n_electrons in range(2, max_electrons + 1): |
| 65 | + molecule = make_atomic_ring(n_electrons, spacing, basis) |
| 66 | + molecule.load() |
| 67 | + molecular_series += [molecule] |
| 68 | + |
| 69 | + # Get plot data. |
| 70 | + x_values = [] |
| 71 | + y_values = [] |
| 72 | + for molecule in molecular_series: |
| 73 | + |
| 74 | + # x-axis. |
| 75 | + x_label = 'Number of Electrons' |
| 76 | + x_values += [molecule.n_electrons] |
| 77 | + |
| 78 | + # y-axis. |
| 79 | + y_label = 'MP2 Energy' |
| 80 | + y_values += [molecule.mp2_energy] |
| 81 | + |
| 82 | + # Print. |
| 83 | + print('\n{} for {} = {}.'.format(x_label, molecule.name, x_values[-1])) |
| 84 | + print('{} for {} = {}.'.format(y_label, molecule.name, y_values[-1])) |
| 85 | + |
| 86 | + # Plot. |
| 87 | + matplotlib.pyplot.figure(0) |
| 88 | + matplotlib.pyplot.plot(x_values, y_values, lw=0, marker='o') |
| 89 | + |
| 90 | + # Set log scales. |
| 91 | + if y_log: |
| 92 | + matplotlib.pyplot.yscale('log') |
| 93 | + if x_log: |
| 94 | + matplotlib.pyplot.xscale('log') |
| 95 | + |
| 96 | + # Finish making the plot. |
| 97 | + matplotlib.pyplot.xticks(size=axis_size) |
| 98 | + matplotlib.pyplot.yticks(size=axis_size) |
| 99 | + matplotlib.pyplot.xlabel(r'%s' % x_label, fontsize=font_size) |
| 100 | + matplotlib.pyplot.ylabel(r'%s' % y_label, fontsize=font_size) |
| 101 | + matplotlib.pyplot.show() |
0 commit comments