33energy calculations.
44
55Copyright 2021 (c) Sarath Menon^1, Yury Lysogorskiy^2, Ralf Drautz^2
6- ^1: Max Planck Institut für Eisenforschung, Dusseldorf, Germany
6+ ^1: Max Planck Institut für Eisenforschung, Dusseldorf, Germany
77^2: Ruhr-University Bochum, Bochum, Germany
88
9- calphy is published and distributed under the Academic Software License v1.0 (ASL).
10- calphy is distributed in the hope that it will be useful for non-commercial academic research,
11- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+ calphy is published and distributed under the Academic Software License v1.0 (ASL).
10+ calphy is distributed in the hope that it will be useful for non-commercial academic research,
11+ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1212calphy API is published and distributed under the BSD 3-Clause "New" or "Revised" License
13- See the LICENSE FILE for more details.
13+ See the LICENSE FILE for more details.
1414
1515More information about the program can be found in:
1616Menon, Sarath, Yury Lysogorskiy, Jutta Rogal, and Ralf Drautz.
3434import pyscal3 .core as pc
3535from pyscal3 .trajectory import Trajectory
3636
37+
3738class LammpsScript :
3839 def __init__ (self ):
3940 self .script = []
@@ -42,12 +43,14 @@ def command(self, command_str):
4243 self .script .append (command_str )
4344
4445 def write (self , infile ):
45- with open (infile , 'w' ) as fout :
46+ with open (infile , "w" ) as fout :
4647 for line in self .script :
47- fout .write (f'{ line } \n ' )
48+ fout .write (f"{ line } \n " )
49+
4850
49- def create_object (cores , directory , timestep , cmdargs = "" ,
50- init_commands = (), script_mode = False ):
51+ def create_object (
52+ cores , directory , timestep , cmdargs = "" , init_commands = (), script_mode = False
53+ ):
5154 """
5255 Create LAMMPS object
5356
@@ -71,28 +74,28 @@ def create_object(cores, directory, timestep, cmdargs="",
7174 else :
7275 if cmdargs == "" :
7376 cmdargs = None
74- lmp = LammpsLibrary (
75- cores = cores , working_directory = directory , cmdargs = cmdargs
76- )
77+ lmp = LammpsLibrary (cores = cores , working_directory = directory , cmdargs = cmdargs )
7778
78- commands = [["units" , "metal" ],
79- ["boundary" , "p p p" ],
80- ["atom_style" , "atomic" ],
81- ["timestep" , str (timestep )],
82- ["box" , "tilt large" ]]
79+ commands = [
80+ ["units" , "metal" ],
81+ ["boundary" , "p p p" ],
82+ ["atom_style" , "atomic" ],
83+ ["timestep" , str (timestep )],
84+ ["box" , "tilt large" ],
85+ ]
8386
8487 if len (init_commands ) > 0 :
85- #we need to replace some initial commands
88+ # we need to replace some initial commands
8689 for rc in init_commands :
87- #split the command
90+ # split the command
8891 raw = rc .split ()
8992 for x in range (len (commands )):
9093 if raw [0 ] == commands [x ][0 ]:
91- #we found a matching command
94+ # we found a matching command
9295 commands [x ] = [rc ]
9396 break
9497 else :
95- #its a new command, add it to the list
98+ # its a new command, add it to the list
9699 commands .append ([rc ])
97100
98101 for command in commands :
@@ -121,12 +124,12 @@ def create_structure(lmp, calc):
121124
122125
123126def set_mass (lmp , options ):
124- if options .mode == ' composition_scaling' :
125- lmp .command (f' mass * { options .mass [- 1 ]} ' )
127+ if options .mode == " composition_scaling" :
128+ lmp .command (f" mass * { options .mass [- 1 ]} " )
126129
127130 else :
128131 for i in range (options .n_elements ):
129- lmp .command (f' mass { i + 1 } { options .mass [i ]} ' )
132+ lmp .command (f" mass { i + 1 } { options .mass [i ]} " )
130133 return lmp
131134
132135
@@ -144,19 +147,21 @@ def set_potential(lmp, options):
144147 -------
145148 lmp : LammpsLibrary object
146149 """
147- #lmp.pair_style(options.pair_style_with_options[0])
148- #lmp.pair_coeff(options.pair_coeff[0])
149- lmp .command (f' pair_style { options ._pair_style_with_options [0 ]} ' )
150- lmp .command (f' pair_coeff { options .pair_coeff [0 ]} ' )
150+ # lmp.pair_style(options.pair_style_with_options[0])
151+ # lmp.pair_coeff(options.pair_coeff[0])
152+ lmp .command (f" pair_style { options ._pair_style_with_options [0 ]} " )
153+ lmp .command (f" pair_coeff { options .pair_coeff [0 ]} " )
151154
152155 lmp = set_mass (lmp , options )
153156
154157 return lmp
155158
159+
156160def read_data (lmp , file ):
157161 lmp .command (f"read_data { file } " )
158162 return lmp
159163
164+
160165def get_structures (file , species , index = None ):
161166 traj = Trajectory (file )
162167 if index is None :
@@ -165,6 +170,7 @@ def get_structures(file, species, index=None):
165170 aseobjs = traj [index ].to_ase (species = species )
166171 return aseobjs
167172
173+
168174def remap_box (lmp , x , y , z ):
169175 lmp .command ("run 0" )
170176 lmp .command (
@@ -222,8 +228,15 @@ def write_data(lmp, file):
222228 lmp .command (f"write_data { file } " )
223229 return lmp
224230
231+
225232def prepare_log (file , screen = False ):
226233 logger = logging .getLogger (__name__ )
234+
235+ # Remove all existing handlers to prevent duplicate logging
236+ for handler in logger .handlers [:]:
237+ handler .close ()
238+ logger .removeHandler (handler )
239+
227240 handler = logging .FileHandler (file )
228241 formatter = logging .Formatter ("%(asctime)s %(name)-12s %(levelname)-8s %(message)s" )
229242 handler .setFormatter (formatter )
@@ -238,6 +251,7 @@ def prepare_log(file, screen=False):
238251 logger .addHandler (scr )
239252 return logger
240253
254+
241255def check_if_any_is_none (data ):
242256 """
243257 Check if any elements of a list is None, if so return True
0 commit comments