The Thermo Class
The thermo class is used to load lammps log files, and to a lesser extent, gromacs .xvg
files
The primary way to create these is using thermotar.create_thermos
, which takes in a path for the LAMMPS
logfile and
returns either one or multiple thermo objects, depending on whether join
and last
are set or not.
Defines a thermo class Thermo Data is extracted from log files
Thermo
Class for loading and operating on LAMMPS thermodynamic output.
Source code in thermotar/thermo.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
|
__getitem__(key)
__init__(thermo_df, *, cleanup=True, properties=None)
Construct a Thermo instance from a pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thermo_df |
DataFrame
|
Pandas DataFrame containing thermodynamic information. |
required |
cleanup |
bool
|
Option to remove c_ etc. prefixes from column names. |
True
|
properties |
Optional[Dict[str, Any]]
|
dict of properties parsed from the log file. Used in create thermos or the get_props class method. |
None
|
Source code in thermotar/thermo.py
__repr__()
block_aves(group_col='Step', n_blocks=5)
Divide the simulation into n_blocks
and take the average of each block.
Used for the calculation of error estimates from a single simulation trajectory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group_col |
Which column to use for splitting the time series into bins. |
'Step'
|
|
n_blocks |
How many bins to use. |
5
|
Returns:
Type | Description |
---|---|
Returns a dataframe with the block number as the index and the properties as
|
|
the columns.
|
|
Source code in thermotar/thermo.py
compare_dist(property, bins=100, n_blocks=5, **kwargs)
Plot the data as a histogram as well as the estimated probability density function. Also plot the gaussian that has the estimated mean and standard deviation.
[!note] These do not correspond to good estimates. Sub averages should be plotted instead. The standard deviation of the gaussian is not the standard error.
Parameters: property: name of the property to plot bins: number of bins to use for the histogram n_blocks: number of blocks to use for the error estimate kwargs: keyword arguments to pass to the plotting functions
Source code in thermotar/thermo.py
compare_dist_samples(property, n_samples=100, **kwargs)
Plot the data as a histogram as well as the estimated probability density function. Also plot the gaussian that has the estimated mean and standard deviation.
Parameters: property: name of the property to plot n_samples: number of sub-averages used. kwargs: keyword arguments to pass to the plotting functions
Source code in thermotar/thermo.py
create_thermos(logfile, join=True, get_properties=True, last=True)
classmethod
Read the output of a lammps simulation from a logfile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
join |
bool
|
Decide whether to concatenate the thermo output of different run commands into one df or not If False a list of thermo objects is returned default: True |
True
|
last |
bool
|
Just get the last set of data, usually production steps.
|
True
|
Source code in thermotar/thermo.py
estimate_drift(time_coord='Step')
Estimate the percentage drift in the thermodynamic properties, by performing linear fits.
The percentage drift is relative to the starting fitted value. If the fitting for the drift estimate fails, the parameters are set to np.nan
Source code in thermotar/thermo.py
estimate_error(group_col='Step', n_blocks=5, error_calc='sem', error_label='err')
Block averaging estimates for the error of the mean and error in the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group_col |
Column to group the data by. Typically "Step" or "Time" |
'Step'
|
|
n_blocks |
Number of blocks to divide the thermo data into. |
5
|
|
error_calc |
Method of estimating the error. Either "sem" or "std". Default "sem" |
'sem'
|
|
error_label |
Suffix appended to error columns, joined by a "_". Default: "err" |
'err'
|
Returns:
Type | Description |
---|---|
A DataFrame with a multi index with an average and error for each property.
|
|
Changes in version 0.0.2:
|
Error columns now have "_err" as suffix by default instead of the value of
|
Source code in thermotar/thermo.py
from_csv(csv_file, **kwargs)
staticmethod
Create a Thermo object from a csv file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
csv_file |
Path
|
path to csv file |
required |
kwargs |
|
{}
|
Source code in thermotar/thermo.py
get_properties(logfile)
staticmethod
Extract non timeseries 'properties' from the logfile.
Currently tries to extract the timestep, lattice size and box size.
Some of these can only be read if the logfile was written from stdout of the lammps simulations rather than from the -log flag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logfile |
Union[str, PathLike]
|
The name of the lammps logfile to read. |
required |
Source code in thermotar/thermo.py
heat_flux(thermostat_C='thermostatC', thermostat_H='thermostatH', area=None, style='linear', axis='z', method='linear_fit', direction=1, real_2_si=True, tstep=None)
Calculate the heatflux from the accumulated energy output.
The heatflux is calculated by linearly fitting to the thermostat_C
and
thermostat_H
columns. This assumes a steady state has been reached and the
heat flux is constant.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thermostat_C |
str
|
Column name of the cold thermostat energy removal |
'thermostatC'
|
thermostat_H |
str
|
Column name of the hot thermostat compute |
'thermostatH'
|
area |
None | float | array
|
If None, work out cross sectional area from properties, if found. If a float, assumes constant area along the axis, If an array, take values. If style is radial, and a float, this is taken to be the radius of the device Default - None |
None
|
style |
str
|
Can be linear or radial atm - the geometry of the system, default: linear |
'linear'
|
axis |
str
|
Name of axis along which heat flux is applied default 'z' |
'z'
|
direction |
int
|
hot to cold = 1, cold to hot = -1 - matches the sign of the thermal gradient |
1
|
Source code in thermotar/thermo.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
parse_thermo(logfile, f=None)
classmethod
Parse thermo data into strings.
This is primarily meant to e aan internal method. Reads the given LAMMPS log file and outputs a list of strings that contain each thermo time series.
An optional argument f is applied to list of strings before returning, for code reusability
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logfile |
Union[str, PathLike]
|
Filename or path to read the logfile from. |
required |
f |
A function that is applied to all found thermos. |
None
|
Source code in thermotar/thermo.py
plot_property(therm_property, x_property=None, **kwargs)
Plot the provieded properties against eachother.
By default therm_property
is plotted against the Step or Time, in that order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
therm_property |
str
|
Which property is plotted on the y-axis |
required |
x_property |
Optional[str]
|
Plot this on the x-axis. If not provided plots against the Step or Time. |
None
|
Source code in thermotar/thermo.py
reverse_cum_average(property)
Calculate the cumulative average in larger and larger chunks.
stats(n_blocks=None)
Compute summary statisitics of the simulation. Optionally compute block into bins first.