@@ -30,20 +30,18 @@ The two methods named *update_log_minimize()* and *update_dump_file()*, are used
3030to print the information in the terminal and in a LAMMPS-type data file, respectively.
3131These two methods will be written in the following.
3232
33- Update the dump and log
34- -----------------------
33+ Create logger
34+ -------------
3535
36- Let us add the following functions named *update_dump_file * and * log_simulation_data *
37- to the * tools.py * file. Here , some variable are being printed in a file, such as box dimension and atom positions .
38- All quantities are dimensionalized before getting outputed, and the file follows
39- a LAMMPS dump format, and can be read by molecular dynamics softwares like VMD .
36+ Let us create functions named *log_simulation_data * to a file named * logger.py *.
37+ With the logger , some output are being printed in a file, as well as in the terminal .
38+ The frequency of printing is set by * thermo_period *, see :ref: ` chapter3-label `.
39+ All quantities are re-dimensionalized before getting outputed .
4040
41- .. label :: start_tools_class
41+ .. label :: start_logger_class
4242
4343.. code-block :: python
4444
45- import numpy as np
46-
4745 import logging
4846 logging.basicConfig(
4947 level = logging.INFO ,
@@ -64,6 +62,48 @@ a LAMMPS dump format, and can be read by molecular dynamics softwares like VMD.
6462 logger.addHandler(console_handler)
6563 logger.addHandler(file_handler)
6664
65+ def log_simulation_data (code ):
66+ if code.thermo_period is not None :
67+ if code.step % code.thermo_period == 0 :
68+ if code.step == 0 :
69+ Epot = code.compute_potential(output = " potential" ) \
70+ * code.reference_energy # kcal/mol
71+ else :
72+ Epot = code.Epot * code.reference_energy # kcal/mol
73+ if code.step == 0 :
74+ if code.thermo_outputs == " Epot" :
75+ logger.info(f " step Epot " )
76+ elif code.thermo_outputs == " Epot-MaxF" :
77+ logger.info(f " step Epot MaxF " )
78+ elif code.thermo_outputs == " Epot-press" :
79+ logger.info(f " step Epot press " )
80+ if code.thermo_outputs == " Epot" :
81+ logger.info(f " { code.step} { Epot:.2f } " )
82+ elif code.thermo_outputs == " Epot-MaxF" :
83+ logger.info(f " { code.step} { Epot:.2f } { code.MaxF:.2f } " )
84+ elif code.thermo_outputs == " Epot-press" :
85+ code.calculate_pressure()
86+ press = code.pressure \
87+ * code.reference_pressure # Atm
88+ logger.info(f " { code.step} { Epot:.2f } { press:.2f } " )
89+
90+ .. label :: end_logger_class
91+
92+ Create dumper
93+ -------------
94+
95+ Let us create a function named *update_dump_file * to a file named
96+ *dumper.py *. The dumper will print a *.lammpstrj file *, which contains the box
97+ dimensions and atom positions at every chosen frame (set by *dumping_period *,
98+ see :ref: `chapter3-label `). All quantities are dimensionalized before getting outputed, and the file follows
99+ a LAMMPS dump format, and can be read by molecular dynamics softwares like VMD.
100+
101+ .. label :: start_dumper_class
102+
103+ .. code-block :: python
104+
105+ import numpy as np
106+
67107 def update_dump_file (code , filename , velocity = False ):
68108 if code.dumping_period is not None :
69109 if code.step % code.dumping_period == 0 :
@@ -110,55 +150,33 @@ a LAMMPS dump format, and can be read by molecular dynamics softwares like VMD.
110150 f.write(characters % (v[0 ], v[1 ], v[2 ],
111151 v[3 ], v[4 ], ' \n ' ))
112152 cpt += 1
113- f.close()
114-
115- def log_simulation_data (code ):
116- if code.thermo_period is not None :
117- if code.step % code.thermo_period == 0 :
118- if code.step == 0 :
119- Epot = code.compute_potential(output = " potential" ) \
120- * code.reference_energy # kcal/mol
121- else :
122- Epot = code.Epot * code.reference_energy # kcal/mol
123- if code.step == 0 :
124- if code.thermo_outputs == " Epot" :
125- logger.info(f " step Epot " )
126- elif code.thermo_outputs == " Epot-MaxF" :
127- logger.info(f " step Epot MaxF " )
128- elif code.thermo_outputs == " Epot-press" :
129- logger.info(f " step Epot press " )
130- if code.thermo_outputs == " Epot" :
131- logger.info(f " { code.step} { Epot:.2f } " )
132- elif code.thermo_outputs == " Epot-MaxF" :
133- logger.info(f " { code.step} { Epot:.2f } { code.MaxF:.2f } " )
134- elif code.thermo_outputs == " Epot-press" :
135- code.calculate_pressure()
136- press = code.pressure \
137- * code.reference_pressure # Atm
138- logger.info(f " { code.step} { Epot:.2f } { press:.2f } " )
153+ f.close()
139154
140- .. label :: end_tools_class
155+ .. label :: end_dumper_class
141156
142157Import the functions
143158--------------------
144159
145- The Monte Carlo and the Minimize class must import *update_dump_file * and *log_simulation_data *.
160+ The Monte Carlo and the Minimize class must both import *update_dump_file *
161+ and *log_simulation_data *. Add these lines at the top of the *MonteCarlo.py * file:
146162
147163.. label :: start_MonteCarlo_class
148164
149165.. code-block :: python
150166
151- from tools import update_dump_file, log_simulation_data
167+ from dumper import update_dump_file
168+ from logger import log_simulation_data
152169
153170 .. label :: end_MonteCarlo_class
154171
155- and
172+ Add the same lines at the top of the * MinimizeEnergy.py * file:
156173
157174.. label :: start_MinimizeEnergy_class
158175
159176.. code-block :: python
160177
161- from tools import update_dump_file, log_simulation_data
178+ from dumper import update_dump_file
179+ from logger import log_simulation_data
162180
163181 .. label :: end_MinimizeEnergy_class
164182
0 commit comments