calphy 1.3.13__py3-none-any.whl → 1.4.2__py3-none-any.whl

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.
calphy/kernel.py CHANGED
@@ -124,7 +124,9 @@ def run_jobs(inputfile):
124
124
  scheduler = pq.SGE(calc.queue.__dict__, cores=calc.queue.cores)
125
125
  else:
126
126
  raise ValueError("Unknown scheduler")
127
-
127
+
128
+ scheduler.queueoptions['jobname'] = ''.join(e for e in identistring if e.isalnum())
129
+
128
130
  #for lattice just provide the number of position
129
131
  scheduler.maincommand = "calphy_kernel -i %s -k %d"%(inputfile,
130
132
  count)
calphy/liquid.py CHANGED
@@ -3,14 +3,14 @@ calphy: a Python library and command line interface for automated free
3
3
  energy calculations.
4
4
 
5
5
  Copyright 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
7
7
  ^2: Ruhr-University Bochum, Bochum, Germany
8
8
 
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.
12
12
  calphy 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.
14
14
 
15
15
  More information about the program can be found in:
16
16
  Menon, Sarath, Yury Lysogorskiy, Jutta Rogal, and Ralf Drautz.
@@ -29,6 +29,7 @@ import calphy.helpers as ph
29
29
  import calphy.phase as cph
30
30
  from calphy.errors import *
31
31
 
32
+
32
33
  class Liquid(cph.Phase):
33
34
  """
34
35
  Class for free energy calculation with liquid as the reference state
@@ -37,7 +38,7 @@ class Liquid(cph.Phase):
37
38
  ----------
38
39
  options : dict
39
40
  dict of input options
40
-
41
+
41
42
  kernel : int
42
43
  the index of the calculation that should be run from
43
44
  the list of calculations in the input file
@@ -46,51 +47,62 @@ class Liquid(cph.Phase):
46
47
  base folder for running calculations
47
48
 
48
49
  """
50
+
49
51
  def __init__(self, calculation=None, simfolder=None, log_to_screen=False):
50
52
  """
51
53
  Set up class
52
54
  """
53
- #call base class
54
- super().__init__(calculation=calculation, simfolder=simfolder, log_to_screen=log_to_screen)
55
-
55
+ # call base class
56
+ super().__init__(
57
+ calculation=calculation, simfolder=simfolder, log_to_screen=log_to_screen
58
+ )
56
59
 
57
60
  def melt_structure(self, lmp):
58
- """
59
- """
61
+ """ """
60
62
  if self.calc._fix_lattice and self.calc.melting_cycle:
61
-
62
- raise ValueError("Cannot fix lattice and melt structure (set to False) at the same time")
63
-
63
+
64
+ raise ValueError(
65
+ "Cannot fix lattice and melt structure (set to False) at the same time"
66
+ )
64
67
 
65
68
  melted = False
66
-
67
- #this is the multiplier for thigh to try melting routines
69
+
70
+ # this is the multiplier for thigh to try melting routines
68
71
  for thmult in np.arange(1.0, 2.0, 0.1):
69
-
72
+
70
73
  trajfile = os.path.join(self.simfolder, "traj.melt")
71
74
  if os.path.exists(trajfile):
72
75
  os.remove(trajfile)
73
76
 
74
- self.logger.info("Starting melting cycle with thigh temp %f, factor %f"%(self.calc._temperature_high, thmult))
75
- factor = (self.calc._temperature_high/self.calc._temperature)*thmult
76
- lmp.velocity("all create", self.calc._temperature*factor, np.random.randint(1, 10000))
77
+ self.logger.info(
78
+ "Starting melting cycle with thigh temp %f, factor %f"
79
+ % (self.calc._temperature_high, thmult)
80
+ )
81
+ factor = (self.calc._temperature_high / self.calc._temperature) * thmult
82
+ lmp.velocity(
83
+ "all create",
84
+ self.calc._temperature * factor,
85
+ np.random.randint(1, 10000),
86
+ )
77
87
  self.fix_nose_hoover(lmp, temp_start_factor=factor, temp_end_factor=factor)
78
88
  lmp.run(int(self.calc.md.n_small_steps))
79
89
  self.unfix_nose_hoover(lmp)
80
-
90
+
81
91
  self.dump_current_snapshot(lmp, "traj.melt")
82
92
 
83
- #we have to check if the structure melted
93
+ # we have to check if the structure melted
84
94
  solids = ph.find_solid_fraction(os.path.join(self.simfolder, "traj.melt"))
85
- self.logger.info("fraction of solids found: %f", solids/self.natoms)
86
- if (solids/self.natoms < self.calc.tolerance.liquid_fraction):
95
+ self.logger.info("fraction of solids found: %f", solids / self.natoms)
96
+ if solids / self.natoms < self.calc.tolerance.liquid_fraction:
87
97
  melted = True
88
98
  break
89
-
90
- #if melting cycle is over and still not melted, raise error
99
+
100
+ # if melting cycle is over and still not melted, raise error
91
101
  if not melted:
92
102
  lmp.close()
93
- raise SolidifiedError("Liquid system did not melt, maybe try a higher thigh temperature.")
103
+ raise SolidifiedError(
104
+ "Liquid system did not melt, maybe try a higher thigh temperature."
105
+ )
94
106
 
95
107
  def run_averaging(self):
96
108
  """
@@ -112,55 +124,58 @@ class Liquid(cph.Phase):
112
124
  threshold value.
113
125
  If `fix_lattice` option is True, then the input structure is used as it is and the corresponding pressure
114
126
  is calculated.
115
- At the end of the run, the averaged box dimensions are calculated.
127
+ At the end of the run, the averaged box dimensions are calculated.
116
128
  """
117
- #create lammps object
118
- lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
119
- self.calc.md.cmdargs, self.calc.md.init_commands)
120
-
121
- lmp.command(f'pair_style {self.calc._pair_style_with_options[0]}')
122
-
123
- #set up structure
129
+ # create lammps object
130
+ lmp = ph.create_object(
131
+ self.cores,
132
+ self.simfolder,
133
+ self.calc.md.timestep,
134
+ self.calc.md.cmdargs,
135
+ self.calc.md.init_commands,
136
+ )
137
+
138
+ lmp.command(f"pair_style {self.calc._pair_style_with_options[0]}")
139
+
140
+ # set up structure
124
141
  lmp = ph.create_structure(lmp, self.calc)
125
142
 
126
- #set up potential
127
- lmp.command(f'pair_coeff {self.calc.pair_coeff[0]}')
143
+ # set up potential
144
+ lmp.command(f"pair_coeff {self.calc.pair_coeff[0]}")
128
145
  lmp = ph.set_mass(lmp, self.calc)
129
146
 
130
- #Melt regime for the liquid
131
- lmp.velocity("all create", self.calc._temperature_high, np.random.randint(1, 10000))
132
-
133
- #add some computes
147
+ # Melt regime for the liquid
148
+ lmp.velocity(
149
+ "all create", self.calc._temperature_high, np.random.randint(1, 10000)
150
+ )
151
+
152
+ # add some computes
134
153
  lmp.command("variable mvol equal vol")
135
154
  lmp.command("variable mlx equal lx")
136
155
  lmp.command("variable mly equal ly")
137
156
  lmp.command("variable mlz equal lz")
138
- lmp.command("variable mpress equal press")
157
+ lmp.command("variable mpress equal press")
139
158
 
140
- #MELT
159
+ # MELT
141
160
  if self.calc.melting_cycle:
142
161
  self.melt_structure(lmp)
143
162
 
144
163
  if not self.calc._fix_lattice:
145
- #now assign correct temperature and equilibrate
164
+ # now assign correct temperature and equilibrate
146
165
  self.run_zero_pressure_equilibration(lmp)
147
166
 
148
- #converge pressure
167
+ # converge pressure
149
168
  self.run_pressure_convergence(lmp)
150
169
  else:
151
170
  self.run_constrained_pressure_convergence(lmp)
152
171
 
153
- #check melted error
172
+ # check melted error
154
173
  self.dump_current_snapshot(lmp, "traj.equilibration_stage1.dat")
155
174
  self.check_if_solidfied(lmp, "traj.equilibration_stage1.dat")
156
175
  self.dump_current_snapshot(lmp, "traj.equilibration_stage2.dat")
157
176
  lmp = ph.write_data(lmp, "conf.equilibration.data")
158
177
  lmp.close()
159
178
 
160
-
161
-
162
-
163
-
164
179
  def run_integration(self, iteration=1):
165
180
  """
166
181
  Run integration routine
@@ -179,55 +194,79 @@ class Liquid(cph.Phase):
179
194
  Run the integration routine where the initial and final systems are connected using
180
195
  the lambda parameter. See algorithm 4 in publication.
181
196
  """
182
- lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
183
- self.calc.md.cmdargs, self.calc.md.init_commands)
197
+ lmp = ph.create_object(
198
+ self.cores,
199
+ self.simfolder,
200
+ self.calc.md.timestep,
201
+ self.calc.md.cmdargs,
202
+ self.calc.md.init_commands,
203
+ )
184
204
 
185
205
  # Adiabatic switching parameters.
186
206
  lmp.command("variable li equal 1.0")
187
207
  lmp.command("variable lf equal 0.0")
188
208
 
209
+ lmp.command(f"pair_style {self.calc._pair_style_with_options[0]}")
189
210
 
190
- lmp.command(f'pair_style {self.calc._pair_style_with_options[0]}')
191
-
192
- #read in the conf file
193
- #conf = os.path.join(self.simfolder, "conf.equilibration.dump")
211
+ # read in the conf file
212
+ # conf = os.path.join(self.simfolder, "conf.equilibration.dump")
194
213
  conf = os.path.join(self.simfolder, "conf.equilibration.data")
195
214
  lmp = ph.read_data(lmp, conf)
196
215
 
197
- #set hybrid ufm and normal potential
198
- #lmp = ph.set_hybrid_potential(lmp, self.options, self.eps)
199
- lmp.command(f'pair_coeff {self.calc.pair_coeff[0]}')
216
+ # set hybrid ufm and normal potential
217
+ # lmp = ph.set_hybrid_potential(lmp, self.options, self.eps)
218
+ lmp.command(f"pair_coeff {self.calc.pair_coeff[0]}")
200
219
  lmp = ph.set_mass(lmp, self.calc)
201
220
 
202
- #remap the box to get the correct pressure
221
+ # remap the box to get the correct pressure
203
222
  lmp = ph.remap_box(lmp, self.lx, self.ly, self.lz)
204
223
 
205
-
206
224
  lmp.command("fix f1 all nve")
207
- lmp.command("fix f2 all langevin %f %f %f %d zero yes"%(self.calc._temperature, self.calc._temperature, self.calc.md.thermostat_damping[1],
208
- np.random.randint(1, 10000)))
209
- lmp.command("run %d"%self.calc.n_equilibration_steps)
225
+ lmp.command(
226
+ "fix f2 all langevin %f %f %f %d zero yes"
227
+ % (
228
+ self.calc._temperature,
229
+ self.calc._temperature,
230
+ self.calc.md.thermostat_damping[1],
231
+ np.random.randint(1, 10000),
232
+ )
233
+ )
234
+ lmp.command("run %d" % self.calc.n_equilibration_steps)
210
235
 
211
236
  lmp.command("unfix f1")
212
237
  lmp.command("unfix f2")
213
238
 
214
- #---------------------------------------------------------------
239
+ # ---------------------------------------------------------------
215
240
  # FWD cycle
216
- #---------------------------------------------------------------
241
+ # ---------------------------------------------------------------
217
242
 
218
243
  lmp.command("variable flambda equal ramp(${li},${lf})")
219
244
  lmp.command("variable blambda equal 1.0-v_flambda")
220
245
 
221
- lmp.command("pair_style hybrid/scaled v_flambda %s v_blambda ufm 7.5"%self.calc._pair_style_with_options[0])
246
+ lmp.command(
247
+ "pair_style hybrid/scaled v_flambda %s v_blambda ufm %f"
248
+ % (self.calc._pair_style_with_options[0], self.ufm_cutoff)
249
+ )
222
250
 
223
- pc = self.calc.pair_coeff[0]
251
+ pc = self.calc.pair_coeff[0]
224
252
  pcraw = pc.split()
225
- pcnew = " ".join([*pcraw[:2], *[self.calc._pair_style_names[0],], *pcraw[2:]])
226
-
227
- lmp.command("pair_coeff %s"%pcnew)
228
- lmp.command("pair_coeff * * ufm %f 1.5"%self.eps)
229
-
230
- lmp.command("compute c1 all pair %s"%self.calc._pair_style_names[0])
253
+ pcnew = " ".join(
254
+ [
255
+ *pcraw[:2],
256
+ *[
257
+ self.calc._pair_style_names[0],
258
+ ],
259
+ *pcraw[2:],
260
+ ]
261
+ )
262
+
263
+ lmp.command("pair_coeff %s" % pcnew)
264
+ lmp.command(
265
+ "pair_coeff * * ufm %f %f"
266
+ % (self.eps, self.calc.uhlenbeck_ford_model.sigma)
267
+ )
268
+
269
+ lmp.command("compute c1 all pair %s" % self.calc._pair_style_names[0])
231
270
  lmp.command("compute c2 all pair ufm")
232
271
 
233
272
  lmp.command("variable step equal step")
@@ -237,17 +276,29 @@ class Liquid(cph.Phase):
237
276
  lmp.command("thermo_style custom step v_dU1 v_dU2")
238
277
  lmp.command("thermo 1000")
239
278
 
240
-
241
- lmp.command("velocity all create %f %d mom yes rot yes dist gaussian"%(self.calc._temperature, np.random.randint(1, 10000)))
279
+ lmp.command(
280
+ "velocity all create %f %d mom yes rot yes dist gaussian"
281
+ % (self.calc._temperature, np.random.randint(1, 10000))
282
+ )
242
283
 
243
284
  lmp.command("fix f1 all nve")
244
- lmp.command("fix f2 all langevin %f %f %f %d zero yes"%(self.calc._temperature, self.calc._temperature, self.calc.md.thermostat_damping[1],
245
- np.random.randint(1, 10000)))
285
+ lmp.command(
286
+ "fix f2 all langevin %f %f %f %d zero yes"
287
+ % (
288
+ self.calc._temperature,
289
+ self.calc._temperature,
290
+ self.calc.md.thermostat_damping[1],
291
+ np.random.randint(1, 10000),
292
+ )
293
+ )
246
294
  lmp.command("compute Tcm all temp/com")
247
295
  lmp.command("fix_modify f2 temp Tcm")
248
296
 
249
- lmp.command("fix f3 all print 1 \"${dU1} ${dU2} ${flambda}\" screen no file forward_%d.dat"%iteration)
250
- lmp.command("run %d"%self.calc._n_switching_steps)
297
+ lmp.command(
298
+ 'fix f3 all print 1 "${dU1} ${dU2} ${flambda}" screen no file forward_%d.dat'
299
+ % iteration
300
+ )
301
+ lmp.command("run %d" % self.calc._n_switching_steps)
251
302
 
252
303
  lmp.command("unfix f1")
253
304
  lmp.command("unfix f2")
@@ -255,39 +306,55 @@ class Liquid(cph.Phase):
255
306
  lmp.command("uncompute c1")
256
307
  lmp.command("uncompute c2")
257
308
 
258
- #---------------------------------------------------------------
309
+ # ---------------------------------------------------------------
259
310
  # EQBRM cycle
260
- #---------------------------------------------------------------
311
+ # ---------------------------------------------------------------
261
312
 
262
- lmp.command("pair_style ufm 7.5")
263
- lmp.command("pair_coeff * * %f 1.5"%self.eps)
313
+ lmp.command("pair_style ufm %f" % self.ufm_cutoff)
314
+ lmp.command(
315
+ "pair_coeff * * %f %f"
316
+ % (self.eps, self.calc.uhlenbeck_ford_model.sigma)
317
+ )
264
318
 
265
319
  lmp.command("thermo_style custom step pe")
266
320
  lmp.command("thermo 1000")
267
321
 
268
322
  lmp.command("fix f1 all nve")
269
- lmp.command("fix f2 all langevin %f %f %f %d zero yes"%(self.calc._temperature, self.calc._temperature, self.calc.md.thermostat_damping[1],
270
- np.random.randint(1, 10000)))
323
+ lmp.command(
324
+ "fix f2 all langevin %f %f %f %d zero yes"
325
+ % (
326
+ self.calc._temperature,
327
+ self.calc._temperature,
328
+ self.calc.md.thermostat_damping[1],
329
+ np.random.randint(1, 10000),
330
+ )
331
+ )
271
332
  lmp.command("fix_modify f2 temp Tcm")
272
333
 
273
- lmp.command("run %d"%self.calc.n_equilibration_steps)
334
+ lmp.command("run %d" % self.calc.n_equilibration_steps)
274
335
 
275
336
  lmp.command("unfix f1")
276
337
  lmp.command("unfix f2")
277
338
 
278
- #---------------------------------------------------------------
339
+ # ---------------------------------------------------------------
279
340
  # BKD cycle
280
- #---------------------------------------------------------------
341
+ # ---------------------------------------------------------------
281
342
 
282
343
  lmp.command("variable flambda equal ramp(${lf},${li})")
283
344
  lmp.command("variable blambda equal 1.0-v_flambda")
284
345
 
285
- lmp.command("pair_style hybrid/scaled v_flambda %s v_blambda ufm 7.5"%self.calc._pair_style_with_options[0])
346
+ lmp.command(
347
+ "pair_style hybrid/scaled v_flambda %s v_blambda ufm %f"
348
+ % (self.calc._pair_style_with_options[0], self.ufm_cutoff)
349
+ )
286
350
 
287
- lmp.command("pair_coeff %s"%pcnew)
288
- lmp.command("pair_coeff * * ufm %f 1.5"%self.eps)
351
+ lmp.command("pair_coeff %s" % pcnew)
352
+ lmp.command(
353
+ "pair_coeff * * ufm %f %f"
354
+ % (self.eps, self.calc.uhlenbeck_ford_model.sigma)
355
+ )
289
356
 
290
- lmp.command("compute c1 all pair %s"%self.calc._pair_style_names[0])
357
+ lmp.command("compute c1 all pair %s" % self.calc._pair_style_names[0])
291
358
  lmp.command("compute c2 all pair ufm")
292
359
 
293
360
  lmp.command("variable step equal step")
@@ -298,22 +365,32 @@ class Liquid(cph.Phase):
298
365
  lmp.command("thermo 1000")
299
366
 
300
367
  lmp.command("fix f1 all nve")
301
- lmp.command("fix f2 all langevin %f %f %f %d zero yes"%(self.calc._temperature, self.calc._temperature, self.calc.md.thermostat_damping[1],
302
- np.random.randint(1, 10000)))
368
+ lmp.command(
369
+ "fix f2 all langevin %f %f %f %d zero yes"
370
+ % (
371
+ self.calc._temperature,
372
+ self.calc._temperature,
373
+ self.calc.md.thermostat_damping[1],
374
+ np.random.randint(1, 10000),
375
+ )
376
+ )
303
377
  lmp.command("fix_modify f2 temp Tcm")
304
378
 
305
- lmp.command("fix f3 all print 1 \"${dU1} ${dU2} ${flambda}\" screen no file backward_%d.dat"%iteration)
306
- lmp.command("run %d"%self.calc._n_switching_steps)
379
+ lmp.command(
380
+ 'fix f3 all print 1 "${dU1} ${dU2} ${flambda}" screen no file backward_%d.dat'
381
+ % iteration
382
+ )
383
+ lmp.command("run %d" % self.calc._n_switching_steps)
307
384
 
308
385
  lmp.command("unfix f1")
309
386
  lmp.command("unfix f2")
310
387
  lmp.command("unfix f3")
311
388
  lmp.command("uncompute c1")
312
389
  lmp.command("uncompute c2")
313
-
314
- #close object
390
+
391
+ # close object
315
392
  lmp.close()
316
-
393
+
317
394
  def thermodynamic_integration(self):
318
395
  """
319
396
  Calculate free energy after integration step
@@ -333,31 +410,35 @@ class Liquid(cph.Phase):
333
410
  """
334
411
  w, q, qerr = find_w(self.simfolder, self.calc, full=True, solid=False)
335
412
 
336
- #TODO: Hardcoded UFM parameters - enable option to change
337
- f1 = get_uhlenbeck_ford_fe(self.calc._temperature,
338
- self.rho, 50, 1.5)
339
-
340
- #Get ideal gas fe
341
- f2 = get_ideal_gas_fe(self.calc._temperature,
342
- self.rho,
343
- self.natoms,
344
- [val['mass'] for key, val in self.calc._element_dict.items()],
345
- [val['composition'] for key, val in self.calc._element_dict.items()])
346
-
413
+ # TODO: Hardcoded UFM parameters - enable option to change
414
+ f1 = get_uhlenbeck_ford_fe(
415
+ self.calc._temperature,
416
+ self.rho,
417
+ self.calc.uhlenbeck_ford_model.p,
418
+ self.calc.uhlenbeck_ford_model.sigma,
419
+ )
420
+
421
+ # Get ideal gas fe
422
+ f2 = get_ideal_gas_fe(
423
+ self.calc._temperature,
424
+ self.rho,
425
+ self.natoms,
426
+ [val["mass"] for key, val in self.calc._element_dict.items()],
427
+ [val["composition"] for key, val in self.calc._element_dict.items()],
428
+ )
429
+
347
430
  self.ferr = qerr
348
431
  self.fref = f1
349
432
  self.fideal = f2
350
433
  self.w = w
351
434
 
352
- #add pressure contribution if required
435
+ # add pressure contribution if required
353
436
  if self.calc._pressure != 0:
354
- p = self.calc._pressure/(10000*160.21766208)
355
- v = self.vol/self.natoms
356
- self.pv = p*v
437
+ p = self.calc._pressure / (10000 * 160.21766208)
438
+ v = self.vol / self.natoms
439
+ self.pv = p * v
357
440
  else:
358
441
  self.pv = 0
359
442
 
360
- #calculate final free energy
443
+ # calculate final free energy
361
444
  self.fe = self.fideal + self.fref - self.w + self.pv
362
-
363
-