@@ -28,9 +28,6 @@ def test_static(self):
2828 diable_log_file = True ,
2929 )
3030 structure = bulk ("Al" , cubic = True ).repeat ([2 , 2 , 2 ])
31- lmp .interactive_lib_command (command = "units lj" )
32- lmp .interactive_lib_command (command = "atom_style atomic" )
33- lmp .interactive_lib_command (command = "atom_modify map array" )
3431 lmp .interactive_structure_setter (
3532 structure = structure ,
3633 units = "lj" ,
@@ -90,9 +87,6 @@ def test_static_with_statement(self):
9087 library = None ,
9188 diable_log_file = True ,
9289 ) as lmp :
93- lmp .interactive_lib_command (command = "units lj" )
94- lmp .interactive_lib_command (command = "atom_style atomic" )
95- lmp .interactive_lib_command (command = "atom_modify map array" )
9690 lmp .interactive_structure_setter (
9791 structure = structure ,
9892 units = "lj" ,
@@ -275,3 +269,106 @@ def test_selective_dynamics_wrong_plane(self):
275269 )
276270 with self .assertRaises (ValueError ):
277271 set_selective_dynamics (structure = atoms , calc_md = False )
272+
273+
274+ class TestBinary (unittest .TestCase ):
275+ def setUp (self ):
276+ self .result = [- 0.04742416 , - 0.97751609 , - 2.66537476 ]
277+ bulk_al = bulk ("Al" , a = 4.0 , cubic = True ).repeat ([2 , 2 , 2 ])
278+ bulk_au = bulk ("Au" , a = 4.0 , cubic = True ).repeat ([2 , 2 , 2 ])
279+ bulk_mix = bulk ("Al" , a = 4.0 , cubic = True ).repeat ([2 , 2 , 2 ])
280+ chemical_symbol_lst = np .array (bulk_mix .get_chemical_symbols ())
281+ chemical_symbol_lst [: int (len (chemical_symbol_lst ) / 2 ) - 1 ] = "Au"
282+ bulk_mix .set_chemical_symbols (chemical_symbol_lst )
283+ self .structure_lst = [bulk_al , bulk_mix , bulk_au ]
284+
285+ @staticmethod
286+ def setup_job (lmp_instance ):
287+ lmp_instance .interactive_lib_command ("pair_style lj/cut 6.0" )
288+ lmp_instance .interactive_lib_command ("pair_coeff 1 1 1.0 1.0 4.0" )
289+ lmp_instance .interactive_lib_command ("pair_coeff 1 2 1.0 1.5 4.0" )
290+ lmp_instance .interactive_lib_command ("pair_coeff 2 2 1.0 2.0 4.0" )
291+ lmp_instance .interactive_lib_command (
292+ command = "thermo_style custom step temp pe etotal pxx pxy pxz pyy pyz pzz vol"
293+ )
294+ lmp_instance .interactive_lib_command (
295+ command = "thermo_modify format float %20.15g"
296+ )
297+
298+ def test_individual_calculation (self ):
299+ energy_lst = []
300+ for structure in self .structure_lst :
301+ lmp = LammpsASELibrary (
302+ working_directory = None ,
303+ cores = 1 ,
304+ comm = None ,
305+ logger = logging .getLogger ("TestStaticLogger" ),
306+ log_file = None ,
307+ library = LammpsLibrary (cores = 2 , mode = "local" ),
308+ diable_log_file = True ,
309+ )
310+ lmp .interactive_structure_setter (
311+ structure = structure ,
312+ units = "lj" ,
313+ dimension = 3 ,
314+ boundary = " " .join (["p" if coord else "f" for coord in structure .pbc ]),
315+ atom_style = "atomic" ,
316+ el_eam_lst = ["Al" , "Au" ],
317+ calc_md = False ,
318+ )
319+ self .setup_job (lmp_instance = lmp )
320+ lmp .interactive_lib_command ("run 0" )
321+ energy_lst .append (lmp .interactive_energy_pot_getter ())
322+ self .assertTrue (np .allclose (self .result , energy_lst ))
323+
324+ def test_interactive_calculation (self ):
325+ energy_lst = []
326+ lmp = LammpsASELibrary (
327+ working_directory = None ,
328+ cores = 1 ,
329+ comm = None ,
330+ logger = logging .getLogger ("TestStaticLogger" ),
331+ log_file = None ,
332+ library = LammpsLibrary (cores = 2 , mode = "local" ),
333+ diable_log_file = True ,
334+ )
335+ for structure in self .structure_lst :
336+ lmp .interactive_structure_setter (
337+ structure = structure ,
338+ units = "lj" ,
339+ dimension = 3 ,
340+ boundary = " " .join (["p" if coord else "f" for coord in structure .pbc ]),
341+ atom_style = "atomic" ,
342+ el_eam_lst = ["Al" , "Au" ],
343+ calc_md = False ,
344+ )
345+ self .setup_job (lmp_instance = lmp )
346+ lmp .interactive_lib_command ("run 0" )
347+ energy_lst .append (lmp .interactive_energy_pot_getter ())
348+ self .assertTrue (np .allclose (self .result , energy_lst ))
349+
350+ def test_interactive_calculation_inverse (self ):
351+ energy_lst = []
352+ lmp = LammpsASELibrary (
353+ working_directory = None ,
354+ cores = 1 ,
355+ comm = None ,
356+ logger = logging .getLogger ("TestStaticLogger" ),
357+ log_file = None ,
358+ library = LammpsLibrary (cores = 2 , mode = "local" ),
359+ diable_log_file = True ,
360+ )
361+ for structure in self .structure_lst [::- 1 ]:
362+ lmp .interactive_structure_setter (
363+ structure = structure ,
364+ units = "lj" ,
365+ dimension = 3 ,
366+ boundary = " " .join (["p" if coord else "f" for coord in structure .pbc ]),
367+ atom_style = "atomic" ,
368+ el_eam_lst = ["Al" , "Au" ],
369+ calc_md = False ,
370+ )
371+ self .setup_job (lmp_instance = lmp )
372+ lmp .interactive_lib_command ("run 0" )
373+ energy_lst .append (lmp .interactive_energy_pot_getter ())
374+ self .assertTrue (np .allclose (self .result , energy_lst [::- 1 ]))
0 commit comments