ipi 2.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. ipi-2.6.0/PKG-INFO +138 -0
  2. ipi-2.6.0/README.md +110 -0
  3. ipi-2.6.0/bin/i-pi +112 -0
  4. ipi-2.6.0/bin/i-pi-committee-reweight +267 -0
  5. ipi-2.6.0/bin/i-pi-contract-trajectory +175 -0
  6. ipi-2.6.0/bin/i-pi-get_Ascp +215 -0
  7. ipi-2.6.0/bin/i-pi-getacf +258 -0
  8. ipi-2.6.0/bin/i-pi-getproperty +63 -0
  9. ipi-2.6.0/bin/i-pi-gleacf +362 -0
  10. ipi-2.6.0/bin/i-pi-kinetic2tag +101 -0
  11. ipi-2.6.0/bin/i-pi-mergebeadspdb +54 -0
  12. ipi-2.6.0/bin/i-pi-mux-positions +172 -0
  13. ipi-2.6.0/bin/i-pi-paraweights +226 -0
  14. ipi-2.6.0/bin/i-pi-planetary +569 -0
  15. ipi-2.6.0/bin/i-pi-posforce2kinetic +145 -0
  16. ipi-2.6.0/bin/i-pi-py_driver +218 -0
  17. ipi-2.6.0/bin/i-pi-remdsort +242 -0
  18. ipi-2.6.0/bin/i-pi-style +109 -0
  19. ipi-2.6.0/bin/i-pi-tests +66 -0
  20. ipi-2.6.0/bin/i-pi-trimsim +228 -0
  21. ipi-2.6.0/drivers/py/__init__.py +0 -0
  22. ipi-2.6.0/drivers/py/driver.py +218 -0
  23. ipi-2.6.0/drivers/py/pes/__init__.py +14 -0
  24. ipi-2.6.0/drivers/py/pes/dummy.py +17 -0
  25. ipi-2.6.0/drivers/py/pes/harmonic.py +30 -0
  26. ipi-2.6.0/drivers/py/pes/rascal.py +57 -0
  27. ipi-2.6.0/ipi/__init__.py +7 -0
  28. ipi-2.6.0/ipi/engine/__init__.py +25 -0
  29. ipi-2.6.0/ipi/engine/atoms.py +273 -0
  30. ipi-2.6.0/ipi/engine/barostats.py +1408 -0
  31. ipi-2.6.0/ipi/engine/beads.py +348 -0
  32. ipi-2.6.0/ipi/engine/cell.py +132 -0
  33. ipi-2.6.0/ipi/engine/ensembles.py +280 -0
  34. ipi-2.6.0/ipi/engine/forcefields.py +1784 -0
  35. ipi-2.6.0/ipi/engine/forces.py +1487 -0
  36. ipi-2.6.0/ipi/engine/initializer.py +663 -0
  37. ipi-2.6.0/ipi/engine/motion/__init__.py +26 -0
  38. ipi-2.6.0/ipi/engine/motion/al6xxx_kmc.py +678 -0
  39. ipi-2.6.0/ipi/engine/motion/alchemy.py +160 -0
  40. ipi-2.6.0/ipi/engine/motion/atomswap.py +135 -0
  41. ipi-2.6.0/ipi/engine/motion/constrained_dynamics.py +541 -0
  42. ipi-2.6.0/ipi/engine/motion/dynamics.py +809 -0
  43. ipi-2.6.0/ipi/engine/motion/geop.py +1005 -0
  44. ipi-2.6.0/ipi/engine/motion/instanton.py +1549 -0
  45. ipi-2.6.0/ipi/engine/motion/motion.py +87 -0
  46. ipi-2.6.0/ipi/engine/motion/multi.py +72 -0
  47. ipi-2.6.0/ipi/engine/motion/neb.py +984 -0
  48. ipi-2.6.0/ipi/engine/motion/phonons.py +448 -0
  49. ipi-2.6.0/ipi/engine/motion/planetary.py +281 -0
  50. ipi-2.6.0/ipi/engine/motion/ramp.py +116 -0
  51. ipi-2.6.0/ipi/engine/motion/replay.py +177 -0
  52. ipi-2.6.0/ipi/engine/motion/scphonons.py +901 -0
  53. ipi-2.6.0/ipi/engine/motion/stringmep.py +1511 -0
  54. ipi-2.6.0/ipi/engine/motion/vscf.py +1473 -0
  55. ipi-2.6.0/ipi/engine/normalmodes.py +905 -0
  56. ipi-2.6.0/ipi/engine/outputs.py +665 -0
  57. ipi-2.6.0/ipi/engine/properties.py +2995 -0
  58. ipi-2.6.0/ipi/engine/simulation.py +402 -0
  59. ipi-2.6.0/ipi/engine/smotion/__init__.py +14 -0
  60. ipi-2.6.0/ipi/engine/smotion/dmd.py +56 -0
  61. ipi-2.6.0/ipi/engine/smotion/metad.py +97 -0
  62. ipi-2.6.0/ipi/engine/smotion/multi.py +62 -0
  63. ipi-2.6.0/ipi/engine/smotion/remd.py +227 -0
  64. ipi-2.6.0/ipi/engine/smotion/smotion.py +58 -0
  65. ipi-2.6.0/ipi/engine/system.py +127 -0
  66. ipi-2.6.0/ipi/engine/thermostats.py +1276 -0
  67. ipi-2.6.0/ipi/external/__init__.py +0 -0
  68. ipi-2.6.0/ipi/external/importlib/__init__.py +5 -0
  69. ipi-2.6.0/ipi/external/importlib/bundledimportlib.py +38 -0
  70. ipi-2.6.0/ipi/inputs/__init__.py +25 -0
  71. ipi-2.6.0/ipi/inputs/atoms.py +133 -0
  72. ipi-2.6.0/ipi/inputs/barostats.py +180 -0
  73. ipi-2.6.0/ipi/inputs/beads.py +152 -0
  74. ipi-2.6.0/ipi/inputs/cell.py +62 -0
  75. ipi-2.6.0/ipi/inputs/ensembles.py +152 -0
  76. ipi-2.6.0/ipi/inputs/forcefields.py +964 -0
  77. ipi-2.6.0/ipi/inputs/forces.py +196 -0
  78. ipi-2.6.0/ipi/inputs/initializer.py +535 -0
  79. ipi-2.6.0/ipi/inputs/interface.py +160 -0
  80. ipi-2.6.0/ipi/inputs/motion/__init__.py +10 -0
  81. ipi-2.6.0/ipi/inputs/motion/al6xxx_kmc.py +269 -0
  82. ipi-2.6.0/ipi/inputs/motion/alchemy.py +98 -0
  83. ipi-2.6.0/ipi/inputs/motion/atomswap.py +101 -0
  84. ipi-2.6.0/ipi/inputs/motion/constrained_dynamics.py +354 -0
  85. ipi-2.6.0/ipi/inputs/motion/dynamics.py +135 -0
  86. ipi-2.6.0/ipi/inputs/motion/geop.py +241 -0
  87. ipi-2.6.0/ipi/inputs/motion/instanton.py +338 -0
  88. ipi-2.6.0/ipi/inputs/motion/motion.py +470 -0
  89. ipi-2.6.0/ipi/inputs/motion/neb.py +326 -0
  90. ipi-2.6.0/ipi/inputs/motion/phonons.py +130 -0
  91. ipi-2.6.0/ipi/inputs/motion/planetary.py +149 -0
  92. ipi-2.6.0/ipi/inputs/motion/ramp.py +157 -0
  93. ipi-2.6.0/ipi/inputs/motion/scphonons.py +189 -0
  94. ipi-2.6.0/ipi/inputs/motion/stringmep.py +317 -0
  95. ipi-2.6.0/ipi/inputs/motion/vscf.py +276 -0
  96. ipi-2.6.0/ipi/inputs/normalmodes.py +169 -0
  97. ipi-2.6.0/ipi/inputs/outputs.py +468 -0
  98. ipi-2.6.0/ipi/inputs/prng.py +123 -0
  99. ipi-2.6.0/ipi/inputs/simulation.py +336 -0
  100. ipi-2.6.0/ipi/inputs/smotion/__init__.py +10 -0
  101. ipi-2.6.0/ipi/inputs/smotion/dmd.py +59 -0
  102. ipi-2.6.0/ipi/inputs/smotion/metad.py +71 -0
  103. ipi-2.6.0/ipi/inputs/smotion/remd.py +85 -0
  104. ipi-2.6.0/ipi/inputs/smotion/smotion.py +154 -0
  105. ipi-2.6.0/ipi/inputs/system.py +231 -0
  106. ipi-2.6.0/ipi/inputs/thermostats.py +389 -0
  107. ipi-2.6.0/ipi/interfaces/__init__.py +8 -0
  108. ipi-2.6.0/ipi/interfaces/sockets.py +915 -0
  109. ipi-2.6.0/ipi/utils/__init__.py +19 -0
  110. ipi-2.6.0/ipi/utils/constrtools.py +530 -0
  111. ipi-2.6.0/ipi/utils/decorators.py +20 -0
  112. ipi-2.6.0/ipi/utils/depend.py +922 -0
  113. ipi-2.6.0/ipi/utils/distance.py +42 -0
  114. ipi-2.6.0/ipi/utils/exchange.py +183 -0
  115. ipi-2.6.0/ipi/utils/hesstools.py +250 -0
  116. ipi-2.6.0/ipi/utils/inputvalue.py +1323 -0
  117. ipi-2.6.0/ipi/utils/instools.py +300 -0
  118. ipi-2.6.0/ipi/utils/io/__init__.py +455 -0
  119. ipi-2.6.0/ipi/utils/io/backends/__init__.py +10 -0
  120. ipi-2.6.0/ipi/utils/io/backends/io_ase.py +109 -0
  121. ipi-2.6.0/ipi/utils/io/backends/io_binary.py +59 -0
  122. ipi-2.6.0/ipi/utils/io/backends/io_json.py +113 -0
  123. ipi-2.6.0/ipi/utils/io/backends/io_pdb.py +201 -0
  124. ipi-2.6.0/ipi/utils/io/backends/io_xyz.py +158 -0
  125. ipi-2.6.0/ipi/utils/io/inputs/__init__.py +10 -0
  126. ipi-2.6.0/ipi/utils/io/inputs/io_xml.py +599 -0
  127. ipi-2.6.0/ipi/utils/io/io_units.py +131 -0
  128. ipi-2.6.0/ipi/utils/mathtools.py +494 -0
  129. ipi-2.6.0/ipi/utils/messages.py +154 -0
  130. ipi-2.6.0/ipi/utils/mintools.py +1629 -0
  131. ipi-2.6.0/ipi/utils/nmtransform.py +489 -0
  132. ipi-2.6.0/ipi/utils/phonontools.py +69 -0
  133. ipi-2.6.0/ipi/utils/prng.py +117 -0
  134. ipi-2.6.0/ipi/utils/softexit.py +189 -0
  135. ipi-2.6.0/ipi/utils/sparse.py +160 -0
  136. ipi-2.6.0/ipi/utils/units.py +374 -0
  137. ipi-2.6.0/ipi.egg-info/PKG-INFO +138 -0
  138. ipi-2.6.0/ipi.egg-info/SOURCES.txt +159 -0
  139. ipi-2.6.0/ipi.egg-info/dependency_links.txt +1 -0
  140. ipi-2.6.0/ipi.egg-info/requires.txt +1 -0
  141. ipi-2.6.0/ipi.egg-info/top_level.txt +1 -0
  142. ipi-2.6.0/ipi_tests/__init__.py +3 -0
  143. ipi-2.6.0/ipi_tests/regression_tests/__init__.py +0 -0
  144. ipi-2.6.0/ipi_tests/regression_tests/runstools.py +245 -0
  145. ipi-2.6.0/ipi_tests/regression_tests/test_run.py +80 -0
  146. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/files_to_check.txt +7 -0
  147. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/init.xyz +3 -0
  148. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/input.xml +40 -0
  149. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/ref_simulation.frc_c.xyz +33 -0
  150. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/ref_simulation.mom_c.xyz +33 -0
  151. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/ref_simulation.out +16 -0
  152. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/ref_simulation.pos_c.xyz +33 -0
  153. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/ref_simulation.vel_c.xyz +33 -0
  154. ipi-2.6.0/ipi_tests/regression_tests/tests/NVE/NVE_1/harmonic_python/test_settings.dat +6 -0
  155. ipi-2.6.0/ipi_tests/test_tools.py +361 -0
  156. ipi-2.6.0/licenses/license_GPL.txt +675 -0
  157. ipi-2.6.0/licenses/license_MIT.txt +21 -0
  158. ipi-2.6.0/pyproject.toml +6 -0
  159. ipi-2.6.0/setup.cfg +39 -0
  160. ipi-2.6.0/setup.py +20 -0
ipi-2.6.0/PKG-INFO ADDED
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.1
2
+ Name: ipi
3
+ Version: 2.6.0
4
+ Summary: A Python interface for ab initio path integral molecular dynamics simulations
5
+ Home-page: http://ipi-code.org
6
+ Author: The i-PI developers
7
+ Author-email: ipi.managers@gmail.com
8
+ Project-URL: Documentation, https://ipi-code.org/i-pi
9
+ Project-URL: Repository, https://github.com/i-pi/i-pi
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: MacOS :: MacOS X
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.6
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
22
+ Classifier: Topic :: Scientific/Engineering :: Physics
23
+ Requires-Python: >=3.6
24
+ Description-Content-Type: text/x-rst
25
+ License-File: licenses/license_GPL.txt
26
+ License-File: licenses/license_MIT.txt
27
+ Requires-Dist: numpy
28
+
29
+ i-PI: a Universal Force Engine
30
+ ==============================
31
+
32
+ A Python interface for ab initio path integral molecular dynamics simulations.
33
+ i-PI is composed of a Python server (i-pi itself, that does not need to be
34
+ compiled but only requires a relatively recent version of Python and Numpy)
35
+ that apply an algorithm that updates the positions of the nuclei, and of an external
36
+ code that acts as a client and computes the electronic energy and forces.
37
+
38
+ This is typically a patched version of an electronic structure code, but a
39
+ simple self-contained Fortran driver that implements several simple interatomic
40
+ potentials is included for test purposes.
41
+
42
+ i-PI was originally developed to simulate the quantum mechanical nature of light
43
+ nuclei by performing path integral molecular dynamics simulations,
44
+ and it implements most of the state-of-the-art methods to accelerate this kind of
45
+ calculations. It has since grown to also provide all sorts of simulation
46
+ strategies, from replica exchange to geometry optimization.
47
+
48
+ Quick Setup and Test
49
+ --------------------
50
+
51
+ To use i-PI with an existing driver, install and update using Pip:
52
+
53
+ Last version::
54
+ ```bash
55
+ python -m pip install git+https://github.com/i-pi/i-pi.git
56
+ ```
57
+
58
+ Last Release::
59
+ ```bash
60
+ pip install -U i-PI
61
+ ```
62
+
63
+ Test with Pytest::
64
+ ```bash
65
+ pip install pytest
66
+ pytest --pyargs ipi.tests
67
+ ```
68
+
69
+ Full installation
70
+ -----------------
71
+
72
+ To develop i-PI or test it with the self-contained driver, follow these
73
+ instructions. It is assumed that i-PI will
74
+ be run from a Linux environment, with a recent version of Python, Numpy and
75
+ gfortran, and that the terminal is initially in the i-pi package directory (the
76
+ directory containing this file), which you can obtain by cloning the repository
77
+
78
+ ```bash
79
+ git clone https://github.com/i-pi/i-pi.git
80
+ ```
81
+
82
+ Source the environment settings file `env.sh` as `source env.sh` or `.
83
+ env.sh`. It is useful to put this in your `.bashrc` or other settings file if
84
+ you always want to have i-PI available.
85
+
86
+
87
+ ### Compile the driver code
88
+
89
+ ```bash
90
+ cd drivers/f90
91
+ make
92
+ cd ../..
93
+ ```
94
+
95
+ ### Examples and demos
96
+
97
+ The `examples` and `demos` folders contain inputs for many different types of
98
+ calculations based on i-PI. Examples are typically minimal use-cases of specific
99
+ features, while demos are more structured, tutorial-like examples that show how
100
+ to realize more complex setups, and also provide a brief discussion of the
101
+ underlying algorithms.
102
+
103
+ To run these examples, you should typically start i-PI, redirecting the output to
104
+ a log file, and then run a couple of instances of the driver code. The progress
105
+ of the wrapper is followed by monitoring the log file with the `tail` Linux command.
106
+
107
+ Optionally, you can make a copy of the directory with the example somewhere
108
+ else if you want to keep the i-PI directory clean. For example
109
+
110
+ ```bash
111
+ cd demos/para-h2-tutorial/tutorial-1/
112
+ i-pi tutorial-1.xml > log &
113
+ i-pi-driver -h localhost -p 31415 -m sg -o 15 &
114
+ i-pi-driver -h localhost -p 31415 -m sg -o 15 &
115
+ tail -f log
116
+ ```
117
+
118
+ The monitoring can be interrupted with CTRL+C when the run has finished (5000 steps).
119
+
120
+
121
+ ### Run the automatic test suite
122
+
123
+ The automatic test suite can be run by calling the i-pi-test script.
124
+ You need to have the `pytest` package installed
125
+
126
+ ```
127
+ i-pi-test
128
+ ```
129
+
130
+ See more details in the README file inside the ipi_tests folder.
131
+
132
+ Contributing
133
+ ------------
134
+
135
+ If you have new features you want to implement into i-PI, your contributions are much welcome.
136
+ See `CONTRIBUTING.md` for a brief set of style guidelines and best practices. Before embarking
137
+ into a substantial project, it might be good to get in touch with the developers, e.g. by opening
138
+ a wishlist issue.
ipi-2.6.0/README.md ADDED
@@ -0,0 +1,110 @@
1
+ i-PI: a Universal Force Engine
2
+ ==============================
3
+
4
+ A Python interface for ab initio path integral molecular dynamics simulations.
5
+ i-PI is composed of a Python server (i-pi itself, that does not need to be
6
+ compiled but only requires a relatively recent version of Python and Numpy)
7
+ that apply an algorithm that updates the positions of the nuclei, and of an external
8
+ code that acts as a client and computes the electronic energy and forces.
9
+
10
+ This is typically a patched version of an electronic structure code, but a
11
+ simple self-contained Fortran driver that implements several simple interatomic
12
+ potentials is included for test purposes.
13
+
14
+ i-PI was originally developed to simulate the quantum mechanical nature of light
15
+ nuclei by performing path integral molecular dynamics simulations,
16
+ and it implements most of the state-of-the-art methods to accelerate this kind of
17
+ calculations. It has since grown to also provide all sorts of simulation
18
+ strategies, from replica exchange to geometry optimization.
19
+
20
+ Quick Setup and Test
21
+ --------------------
22
+
23
+ To use i-PI with an existing driver, install and update using Pip:
24
+
25
+ Last version::
26
+ ```bash
27
+ python -m pip install git+https://github.com/i-pi/i-pi.git
28
+ ```
29
+
30
+ Last Release::
31
+ ```bash
32
+ pip install -U i-PI
33
+ ```
34
+
35
+ Test with Pytest::
36
+ ```bash
37
+ pip install pytest
38
+ pytest --pyargs ipi.tests
39
+ ```
40
+
41
+ Full installation
42
+ -----------------
43
+
44
+ To develop i-PI or test it with the self-contained driver, follow these
45
+ instructions. It is assumed that i-PI will
46
+ be run from a Linux environment, with a recent version of Python, Numpy and
47
+ gfortran, and that the terminal is initially in the i-pi package directory (the
48
+ directory containing this file), which you can obtain by cloning the repository
49
+
50
+ ```bash
51
+ git clone https://github.com/i-pi/i-pi.git
52
+ ```
53
+
54
+ Source the environment settings file `env.sh` as `source env.sh` or `.
55
+ env.sh`. It is useful to put this in your `.bashrc` or other settings file if
56
+ you always want to have i-PI available.
57
+
58
+
59
+ ### Compile the driver code
60
+
61
+ ```bash
62
+ cd drivers/f90
63
+ make
64
+ cd ../..
65
+ ```
66
+
67
+ ### Examples and demos
68
+
69
+ The `examples` and `demos` folders contain inputs for many different types of
70
+ calculations based on i-PI. Examples are typically minimal use-cases of specific
71
+ features, while demos are more structured, tutorial-like examples that show how
72
+ to realize more complex setups, and also provide a brief discussion of the
73
+ underlying algorithms.
74
+
75
+ To run these examples, you should typically start i-PI, redirecting the output to
76
+ a log file, and then run a couple of instances of the driver code. The progress
77
+ of the wrapper is followed by monitoring the log file with the `tail` Linux command.
78
+
79
+ Optionally, you can make a copy of the directory with the example somewhere
80
+ else if you want to keep the i-PI directory clean. For example
81
+
82
+ ```bash
83
+ cd demos/para-h2-tutorial/tutorial-1/
84
+ i-pi tutorial-1.xml > log &
85
+ i-pi-driver -h localhost -p 31415 -m sg -o 15 &
86
+ i-pi-driver -h localhost -p 31415 -m sg -o 15 &
87
+ tail -f log
88
+ ```
89
+
90
+ The monitoring can be interrupted with CTRL+C when the run has finished (5000 steps).
91
+
92
+
93
+ ### Run the automatic test suite
94
+
95
+ The automatic test suite can be run by calling the i-pi-test script.
96
+ You need to have the `pytest` package installed
97
+
98
+ ```
99
+ i-pi-test
100
+ ```
101
+
102
+ See more details in the README file inside the ipi_tests folder.
103
+
104
+ Contributing
105
+ ------------
106
+
107
+ If you have new features you want to implement into i-PI, your contributions are much welcome.
108
+ See `CONTRIBUTING.md` for a brief set of style guidelines and best practices. Before embarking
109
+ into a substantial project, it might be good to get in touch with the developers, e.g. by opening
110
+ a wishlist issue.
ipi-2.6.0/bin/i-pi ADDED
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """Main script from which the simulation is run.
4
+
5
+ Deals with creation of the simulation object, reading the input file and
6
+ initialising the system.
7
+
8
+ Run using:
9
+ i-pi input_file.xml
10
+
11
+ Where 'input_file.xml' should be replaced by the name of the xml input file
12
+ from which the system data will be read. For a description of how the input
13
+ file should be formatted, see the reference manual.
14
+ """
15
+
16
+ # This file is part of i-PI.
17
+ # i-PI Copyright (C) 2014-2015 i-PI developers
18
+ # See the "licenses" directory for full license information.
19
+
20
+
21
+ import sys
22
+ import os
23
+
24
+ # Check that we have the import path for this i-PI set and if not, add it.
25
+ dir_root = os.path.realpath(
26
+ os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
27
+ if not dir_root in sys.path:
28
+ sys.path.insert(0, dir_root)
29
+
30
+ from ipi.utils.softexit import softexit
31
+ from ipi.engine.simulation import Simulation
32
+
33
+ def profile_exit(prefix="profile"):
34
+ # write out the outputs of the profiler
35
+ import yappi
36
+ yappi.stop()
37
+ yappi.get_thread_stats().print_all()
38
+ yfs = yappi.get_func_stats()
39
+ yfs.save(prefix+".kgrind", type="callgrind")
40
+ ypo = open(prefix+".yappi", "w")
41
+ yfs.print_all(out=ypo)
42
+ ypo.close()
43
+
44
+
45
+ def main(fn_input, options):
46
+ """Loads and runs the simulation stored in `fn_input`."""
47
+
48
+ # optionally profile this run - set up
49
+ if options.do_yappi:
50
+ try:
51
+ import yappi
52
+ yappi.set_clock_type(options.yappi_clock)
53
+ yappi.start(builtins=True, profile_threads=True)
54
+ # register the output function for the profiler so it is
55
+ # called whatever the way i-PI ends
56
+ softexit.register_function(profile_exit, prefix=options.yappi_prefix)
57
+ except ImportError:
58
+ raise ImportError('Profiling requires the `yappi` package.')
59
+
60
+ # construct simulation based on input file
61
+ simulation = Simulation.load_from_xml(fn_input, request_banner=True, custom_verbosity=options.verbosity)
62
+
63
+ # run the simulation
64
+ simulation.run()
65
+
66
+ # It seems that checkpoints are written by the following.
67
+ # TODO: Have them written when simulation.run() finishes instead.
68
+ # It should be sufficient to run `self.softexit() at the end of
69
+ # `Simulation.run()`. Anything else missing?
70
+ softexit.trigger(status="success", message=" @ SIMULATION: Exiting cleanly.")
71
+
72
+
73
+ if __name__ == '__main__':
74
+
75
+ # TODO: Use argparse once we move to Python 2.7.
76
+
77
+ from optparse import OptionParser
78
+
79
+ parser = OptionParser(usage='%prog [options] <input file>',
80
+ description='The main i-PI executable used to run '
81
+ 'a simulation, given an XML input file.'
82
+ )
83
+
84
+ parser.add_option('-p', '--profile',
85
+ action='store_true', dest='do_yappi', default=False,
86
+ help='Profile this run using yappi.')
87
+
88
+ parser.add_option('--profiler-clock', dest='yappi_clock', default="cpu",
89
+ choices=['cpu', 'wall'],
90
+ help='Type of profiling timing: `wall` for wall-clock timing, and `cpu` for CPU timing.')
91
+
92
+ parser.add_option('--profiler-output', dest='yappi_prefix', default="profile",
93
+ help='Prefix for profiler files.')
94
+
95
+ parser.add_option('-V', '--verbosity', dest='verbosity', default=None,
96
+ choices=['quiet', 'low', 'medium', 'high', 'debug'],
97
+ help='Define the verbosity level.')
98
+
99
+ options, args = parser.parse_args()
100
+
101
+ # make sure that we have exactly one input file and it exists
102
+ if len(args) == 0:
103
+ parser.error('No input file name provided.')
104
+ elif len(args) > 1:
105
+ parser.error('Provide only one input file name.')
106
+ else:
107
+ fn_in = args[0]
108
+ if not os.path.exists(fn_in):
109
+ parser.error('Input file not found: {:s}'.format(fn_in))
110
+
111
+ # Everything is ready. Go!
112
+ main(args[0], options)
@@ -0,0 +1,267 @@
1
+ #!/usr/bin/env python3
2
+ import sys
3
+ import argparse
4
+ import numpy as np
5
+ from ipi.engine.simulation import Simulation
6
+
7
+
8
+ def direct_reweight(pot, obs, kbT):
9
+ """
10
+ Reweights an observable based on a committee of potentials, at the temperature kT
11
+ ref:
12
+ Torrie, Glenn M., and John P. Valleau. "Nonphysical sampling distributions in Monte
13
+ Carlo free-energy estimation: Umbrella sampling."
14
+ Journal of Computational Physics 23.2 (1977): 187-199.
15
+ https://doi.org/10.1016/0021-9991(77)90121-8
16
+
17
+ Inputs:
18
+ pot : an array (nframes x ncommittee) containing the values of the potentials for each committee
19
+ obs : an array containing the values of the observables
20
+ kbT : the temperature, in energy units
21
+
22
+ Returns:
23
+ obs_avg_rew : the observable reweighted for each potential
24
+ weights : the weights computed for each model and frame
25
+ """
26
+ beta = 1.0 / kbT
27
+ num_pot_frames = pot.shape[0]
28
+ num_obs_frames = obs.shape[0]
29
+ if num_pot_frames != num_obs_frames:
30
+ raise RuntimeError(
31
+ "Potential and observable files have different numbers of frames"
32
+ )
33
+
34
+ num_pot_models = pot.shape[1]
35
+ if obs.ndim == 1:
36
+ obs = np.expand_dims(obs, axis=1)
37
+
38
+ # vectorized evaluation of weights
39
+ weights = np.array(-beta * (pot.T - np.mean(pot, axis=1)).T, dtype=np.float128)
40
+ weights = np.exp(weights)
41
+
42
+ # 1-d array of lenght num_pot_models: normalization of the weights over frames
43
+ norm = np.sum(weights, axis=0)
44
+ for i in range(num_pot_models):
45
+ weights[:, i] /= norm[i]
46
+ obs_avg_rew = obs.T @ weights
47
+
48
+ return obs_avg_rew, weights
49
+
50
+
51
+ def CEA(pot, obs, kbT):
52
+ """
53
+ Reweights the quantity by cumulant expansion approximation (CEA)
54
+ ref:
55
+ Michele Ceriotti, Guy A. R. Brain, Oliver Riordan and David E.
56
+ Manolopoulos 2011 The inefficiency of re-weighted sampling and
57
+ the curse of system size in high-order path integration
58
+ Proc. R. Soc. A.4682–17
59
+ http://doi.org/10.1098/rspa.2011.0413
60
+
61
+ Inputs:
62
+ pot : an array (nframes x ncommittee) containing the values of the potentials for each committee
63
+ obs : an array containing the values of the observables
64
+ kbT : the temperature, in energy units
65
+
66
+ Returns:
67
+ obs_avg_rew : the observable reweighted for each potential
68
+ weights : the weights computed for each model and frame
69
+
70
+ """
71
+ beta = 1.0 / kbT
72
+ num_pot_frames = pot.shape[0]
73
+ num_obs_frames = obs.shape[0]
74
+ if num_pot_frames != num_obs_frames:
75
+ raise RuntimeError(
76
+ "Potential and observable files have different numbers of frames"
77
+ )
78
+ num_pot_models = pot.shape[1]
79
+ if obs.ndim == 1:
80
+ obs = np.expand_dims(obs, axis=1)
81
+ num_obs_models = obs.shape[1]
82
+
83
+ # get the h matrix h = beta(V^i - barV)
84
+ h_matrix = np.zeros((num_pot_frames, num_pot_models))
85
+ # fast way avoiding double loop
86
+ h_matrix = beta * (pot.T - np.mean(pot, axis=1)).T
87
+ # get frame-average of h, h_avg
88
+ h_avg = np.mean(h_matrix, axis=0) # 1d-array of length num_pot_models
89
+ # get frame-average of observable, obs_avg
90
+ obs_avg = np.mean(obs, axis=0) # 1d-array of length num_obs_models
91
+ # get frame-average of the product between the observable and h, obsxh_avg
92
+ obsxh_avg = (obs.T @ h_matrix) / num_pot_frames
93
+ # get frame-average of observable, reweighted according to the CEA, obs_avg_CEA
94
+ obs_avg_CEA = np.zeros((num_obs_models, num_pot_models))
95
+ for j in range(num_obs_models):
96
+ for i in range(num_pot_models):
97
+ obs_avg_CEA[j, i] = obs_avg[j] - obsxh_avg[j, i] + obs_avg[j] * h_avg[i]
98
+ return obs_avg_CEA, h_matrix
99
+
100
+
101
+ def uncertainty_CEA_multiple_models(pot, obs, kbT):
102
+ """
103
+ Reweights the quantity by cumulant expansion approximation (CEA) in the case of
104
+ multiple models used to predict the observable.
105
+ ref:
106
+ Michele Ceriotti, Guy A. R. Brain, Oliver Riordan and David E.
107
+ Manolopoulos 2011 The inefficiency of re-weighted sampling and
108
+ the curse of system size in high-order path integration
109
+ Proc. R. Soc. A.4682–17
110
+ http://doi.org/10.1098/rspa.2011.0413
111
+
112
+ Inputs:
113
+ pot : an array (nframes x ncommittee) containing the values of the potentials for each committee
114
+ obs : an array containing the values of the observables
115
+ kbT : the temperature, in energy units
116
+
117
+ Returns:
118
+ mean_value : the average value of the observable
119
+ sigma2_a : the uncertainty related to the models used to predict the observable
120
+ sigma2_aV : the uncertainty related to the use of a committee of potentials driving the dynamics
121
+ sigma2_tile : the total uncertainty for the observable
122
+
123
+ """
124
+ beta = 1.0 / kbT # noqa
125
+ obs_avg = np.mean(obs, axis=0)
126
+ obs_avg_CEA, _h_matrix = CEA(obs, pot, kbT)
127
+ fac_a = (pot.shape[1] * (obs.shape[1] - 1)) / (pot.shape[1] * obs.shape[1] - 1)
128
+ fac_aV = ((pot.shape[1] - 1) * obs.shape[1]) / (pot.shape[1] * obs.shape[1] - 1)
129
+ sigma2_a = np.var(obs_avg, ddof=1) # Eq.(27)
130
+ sigma2_aV = np.mean(np.var(obs_avg_CEA, axis=1, ddof=1)) # Eq.(28)
131
+ sigma2_tilde = fac_a * sigma2_a + fac_aV * sigma2_aV # Eq.(26)
132
+ return np.mean(obs_avg), sigma2_a, sigma2_aV, sigma2_tilde
133
+
134
+
135
+ def commitee_reweight(
136
+ path2ixml, pot_file, obs_file, stride=1, index=-1, direct=False, multi_models=False
137
+ ):
138
+ """
139
+ Parameters
140
+ ----------
141
+ pot_file : str, mandatory
142
+ The file containing the values of the potential from each model, either in .dat form or as .extra.
143
+ Each line contains the potentials for the M models for each frame
144
+ obs_file : str, mandatory
145
+ A file containing the value of the observable for each frame.
146
+ It is assumed that lines correspond to frames, while columns to properties.
147
+ Multiple properties can be reweighted at the same time.
148
+ stride : integer, [1]
149
+ The frequency of sampling of pot_file, if different from that of prop_file (e.g. --stride 10 if
150
+ the potential was printed 10 times more often than the observable. --stride -10 must be used if
151
+ the observable were printed more often than the potential).
152
+ index : integer, optional
153
+ Which column of the property file should be used to compute the average and uncertainty.
154
+ If it is not given, and there are multiple columns, they will be interpreted as corresponding
155
+ to multiple property models
156
+ direct : bool, optional
157
+ Activates the direct reweighting, instead of the cumulant expansion approximation.
158
+ Use at your own risk! Does not work with multi_models
159
+ multi_models: bool, optional
160
+ Activates the uncertainty for multiple models, as in Eqs. 26,27,28 of the paper.
161
+ It considers each column as a prediction from a single model and returns the
162
+ uncertainty of the models together with the uncertainty of the potentials.
163
+
164
+ """
165
+ if index >= 0:
166
+ obs = np.loadtxt(obs_file, usecols=index)
167
+ else:
168
+ obs = np.loadtxt(obs_file)
169
+
170
+ if stride > 0:
171
+ potentials = np.loadtxt(pot_file)[::stride]
172
+ elif stride < 0:
173
+ stride = np.abs(stride)
174
+ obs = obs[::stride]
175
+ else:
176
+ raise ValueError("Stride value cannot be zero")
177
+
178
+ # Load kbT from i-PI, we could make it into a small function
179
+ simul = Simulation.load_from_xml(
180
+ path2ixml, custom_verbosity="quiet", read_only=True
181
+ )
182
+ kbT = float(simul.syslist[0].ensemble.temp)
183
+
184
+ if multi_models:
185
+ mean_value, sigma2_a, sigma2_aV, sigma2_tilde = uncertainty_CEA_multiple_models(
186
+ potentials, obs, kbT
187
+ )
188
+ print("# Mean Error sigma_a sigma_aV")
189
+ print(
190
+ "{:.8e} {:.8e} {:.8e} {:.8e}".format(
191
+ mean_value, np.sqrt(sigma2_tilde), np.sqrt(sigma2_a), np.sqrt(sigma2_aV)
192
+ )
193
+ )
194
+ else:
195
+ # CEA is the default choice. The weights or h_matrix are
196
+ if direct:
197
+ rw_obs, _weights = direct_reweight(potentials, obs, kbT)
198
+ else:
199
+ rw_obs, _h_matrix = CEA(potentials, obs, kbT)
200
+ print(
201
+ "# Mean Error <committee_1> .... <committee_N>"
202
+ )
203
+
204
+ np.savetxt(
205
+ sys.stdout,
206
+ np.vstack([rw_obs.mean(axis=1), rw_obs.std(axis=1), rw_obs.T]).T,
207
+ fmt="% 15.8e ",
208
+ )
209
+
210
+
211
+ if __name__ == "__main__":
212
+ parser = argparse.ArgumentParser(
213
+ description="""This tool exploits a committee of ML models to compute the reweighted canonical averages of a given observable, in order to quantify its uncertainty at thermodynamic equilibrium.
214
+ The units for the potentials are assumed to be Hartree.
215
+ The full methodology is described in: https://doi.org/10.1063/5.0036522"""
216
+ )
217
+
218
+ parser.add_argument(
219
+ "input_xml",
220
+ type=str,
221
+ help="The path to the input file used to run the simulation (usually input.xml)",
222
+ )
223
+ parser.add_argument(
224
+ "pot_file",
225
+ type=str,
226
+ help="The file containing the potentials. Rows = frames, columns = potentials",
227
+ )
228
+ parser.add_argument(
229
+ "obs_file",
230
+ type=str,
231
+ help="The file containing the properties. Rows = frames, columns = property/ies",
232
+ )
233
+ parser.add_argument(
234
+ "--stride",
235
+ type=int,
236
+ default=1,
237
+ help="The stride ratio used to print the potential and the property. A positive number will take one every n-th value of the potential. A negative number will do the same on the property file.",
238
+ )
239
+ parser.add_argument(
240
+ "--index",
241
+ type=int,
242
+ default=-1,
243
+ help="0-based index of the property that we want to compute",
244
+ )
245
+ parser.add_argument(
246
+ "--direct",
247
+ action="store_true",
248
+ help="Call this option to activate direct reweighting. Standard reweighting is the CEA",
249
+ )
250
+ parser.add_argument(
251
+ "--multi-obs",
252
+ action="store_true",
253
+ help="Call this option to activate reweighting for multiple observable models. The obs_file is interpreted as having one row per step, and columns correspond to the members of a property committee. It returns both the uncertainty associated with the spread of the observable models, and the one derived from the reweighting due to the potential models",
254
+ )
255
+
256
+ args = parser.parse_args()
257
+ sys.exit(
258
+ commitee_reweight(
259
+ args.input_xml,
260
+ args.pot_file,
261
+ args.obs_file,
262
+ args.stride,
263
+ args.index,
264
+ args.direct,
265
+ args.multi_obs,
266
+ )
267
+ )