@@ -85,9 +85,9 @@ All quantities are re-dimensionalized before getting outputed.
8585 if code.step % code.thermo_period == 0 :
8686 if code.step == 0 :
8787 Epot = code.compute_potential() \
88- * code.reference_energy # kcal/mol
88+ * code.ref_energy # kcal/mol
8989 else :
90- Epot = code.Epot * code.reference_energy # kcal/mol
90+ Epot = code.Epot * code.ref_energy # kcal/mol
9191 if code.step == 0 :
9292 if code.thermo_outputs == " Epot" :
9393 logger.info(f " step Epot " )
@@ -101,7 +101,7 @@ All quantities are re-dimensionalized before getting outputed.
101101 logger.info(f " { code.step} { Epot:.2f } { code.MaxF:.2f } " )
102102 elif code.thermo_outputs == " Epot-press" :
103103 code.calculate_pressure()
104- press = code.pressure * code.reference_pressure # Atm
104+ press = code.pressure * code.ref_pressure # Atm
105105 logger.info(f " { code.step} { Epot:.2f } { press:.2f } " )
106106
107107 .. label :: end_logger_class
@@ -125,14 +125,12 @@ a LAMMPS dump format, and can be read by molecular dynamics softwares like VMD.
125125 if code.dumping_period is not None :
126126 if code.step % code.dumping_period == 0 :
127127 # Convert units to the *real* dimensions
128- box_boundaries = code.box_boundaries\
129- * code.reference_distance # Angstrom
130- atoms_positions = code.atoms_positions\
131- * code.reference_distance # Angstrom
128+ box_boundaries = code.box_boundaries* code.ref_length # Angstrom
129+ atoms_positions = code.atoms_positions* code.ref_length # Angstrom
132130 atoms_types = code.atoms_type
133131 if velocity:
134132 atoms_velocities = code.atoms_velocities \
135- * code.reference_distance / code.reference_time # Angstrom/femtosecond
133+ * code.ref_length / code.ref_time # Angstrom/femtosecond
136134 # Start writting the file
137135 if code.step == 0 : # Create new file
138136 f = open (code.data_folder + filename, " w" )
@@ -141,18 +139,18 @@ a LAMMPS dump format, and can be read by molecular dynamics softwares like VMD.
141139 f.write(" ITEM: TIMESTEP\n " )
142140 f.write(str (code.step) + " \n " )
143141 f.write(" ITEM: NUMBER OF ATOMS\n " )
144- f.write(str (code.total_number_atoms ) + " \n " )
142+ f.write(str (np.sum( code.number_atoms) ) + " \n " )
145143 f.write(" ITEM: BOX BOUNDS pp pp pp\n " )
146144 for dim in np.arange(3 ):
147- f.write(str (box_boundaries[dim][0 ]) + " "
148- + str (box_boundaries[dim][1 ]) + " \n " )
145+ f.write(str (box_boundaries[dim][0 ].magnitude ) + " "
146+ + str (box_boundaries[dim][1 ].magnitude ) + " \n " )
149147 cpt = 1
150148 if velocity:
151149 f.write(" ITEM: ATOMS id type x y z vx vy vz\n " )
152150 characters = " %d %d %.3f %.3f %.3f %.3f %.3f %.3f %s "
153151 for type , xyz, vxyz in zip (atoms_types,
154- atoms_positions,
155- atoms_velocities):
152+ atoms_positions.magnitude ,
153+ atoms_velocities.magnitude ):
156154 v = [cpt, type , xyz[0 ], xyz[1 ], xyz[2 ],
157155 vxyz[0 ], vxyz[1 ], vxyz[2 ]]
158156 f.write(characters % (v[0 ], v[1 ], v[2 ], v[3 ], v[4 ],
@@ -162,7 +160,7 @@ a LAMMPS dump format, and can be read by molecular dynamics softwares like VMD.
162160 f.write(" ITEM: ATOMS id type x y z\n " )
163161 characters = " %d %d %.3f %.3f %.3f %s "
164162 for type , xyz in zip (atoms_types,
165- atoms_positions):
163+ atoms_positions.magnitude ):
166164 v = [cpt, type , xyz[0 ], xyz[1 ], xyz[2 ]]
167165 f.write(characters % (v[0 ], v[1 ], v[2 ],
168166 v[3 ], v[4 ], ' \n ' ))
@@ -197,6 +195,35 @@ Add the same lines at the top of the *MinimizeEnergy.py* file:
197195
198196 .. label :: end_MinimizeEnergy_class
199197
198+ Finally, let us make sure that *thermo_period *, *dumping_period *, and *thermo_outputs *
199+ parameters are passed the InitializeSimulation method:
200+
201+ .. label :: start_InitializeSimulation_class
202+
203+ .. code-block :: python
204+
205+ def __init__ (self ,
206+ (...)
207+ neighbor= 1 , # Integer
208+ thermo_period = None ,
209+ dumping_period = None ,
210+ thermo_outputs = None ,
211+
212+ .. label :: end_InitializeSimulation_class
213+
214+ .. label :: start_InitializeSimulation_class
215+
216+ .. code-block :: python
217+
218+ def __init__ (self ,
219+ (...)
220+ self .initial_positions = initial_positions
221+ self .thermo_period = thermo_period
222+ self .dumping_period = dumping_period
223+ self .thermo_outputs = thermo_outputs
224+
225+ .. label :: end_InitializeSimulation_class
226+
200227Test the code
201228-------------
202229
@@ -208,21 +235,38 @@ files were indeed created without the *Outputs/* folder:
208235
209236.. code-block :: python
210237
211- import os
212238 from MinimizeEnergy import MinimizeEnergy
239+ from pint import UnitRegistry
240+ ureg = UnitRegistry()
241+ import os
213242
214- # Initialize the MinimizeEnergy object and run the minimization
243+ # Define atom number of each group
244+ nmb_1, nmb_2= [2 , 3 ]
245+ # Define LJ parameters (sigma)
246+ sig_1, sig_2 = [3 , 4 ]* ureg.angstrom
247+ # Define LJ parameters (epsilon)
248+ eps_1, eps_2 = [0.2 , 0.4 ]* ureg.kcal/ ureg.mol
249+ # Define atom mass
250+ mss_1, mss_2 = [10 , 20 ]* ureg.gram/ ureg.mol
251+ # Define box size
252+ L = 20 * ureg.angstrom
253+ # Define a cut off
254+ rc = 2.5 * sig_1
255+
256+ # Initialize the prepare object
215257 minimizer = MinimizeEnergy(
258+ ureg = ureg,
216259 maximum_steps = 100 ,
217260 thermo_period = 25 ,
218261 dumping_period = 25 ,
219- thermo_outputs = " Epot-MaxF " ,
220- number_atoms = [ 2 , 3 ],
221- epsilon = [ 0.1 , 1.0 ], # kcal/mol
222- sigma = [ 3 , 4 ], # A
223- atom_mass = [ 10 , 20 ], # g/mol
224- box_dimensions = [ 20 , 20 , 20 ], # A
262+ number_atoms = [nmb_1, nmb_2] ,
263+ epsilon = [eps_1, eps_2], # kcal/mol
264+ sigma = [sig_1, sig_2 ], # A
265+ atom_mass = [mss_1, mss_2 ], # g/mol
266+ box_dimensions = [L, L, L ], # A
267+ cut_off = rc,
225268 data_folder = " Outputs/" ,
269+ thermo_outputs = " Epot-MaxF" ,
226270 )
227271 minimizer.run()
228272
0 commit comments