I/O¶
PACKMOL¶
mdinterface.build.box.PackmolError
¶
Bases: RuntimeError
PACKMOL execution or output-processing failure.
Source code in mdinterface/build/box.py
Reading structures¶
mdinterface.io.read.read_lammps_data_file(filename, pbc=False, ato_start_idx=0, is_snippet=False)
¶
Read a LAMMPS data file into ASE atoms and mdinterface topology objects.
Supports full and atomic atom styles with LJ (lj/cut...) pair coefficients,
harmonic bonds and angles, OPLS or five-term multi/harmonic dihedrals and
CVFF impropers. Section
style comments and the number of values per row are validated, velocities
and type-label sections are ignored, and atoms may appear in any ID order.
PairIJ Coeffs are accepted when cross terms follow geometric mixing.
Missing coefficient sections leave the corresponding parameters unset and
log a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or path - like
|
LAMMPS data file. |
required |
pbc
|
bool
|
Keep the periodic cell; otherwise the cell and periodicity are removed. |
False
|
ato_start_idx
|
int
|
Offset added to atom indices in generated atom-type labels. |
0
|
is_snippet
|
bool
|
Mark generated atom-type labels as belonging to a parameterization snippet. |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file contains unsupported sections or styles, or coefficients are missing for individual types. |
Source code in mdinterface/io/read.py
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 | |
mdinterface.io.read.read_lammps_nth_frame(filename, frame=-1)
¶
Read a single frame from a LAMMPS dump file without loading the full trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the LAMMPS dump file. |
required |
frame
|
int
|
Frame index. |
-1
|
Returns:
| Type | Description |
|---|---|
Atoms
|
The requested frame as an ASE Atoms object with cell and PBC set. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the requested frame index is out of range. |
Source code in mdinterface/io/read.py
GROMACS writer¶
Warning
GROMACS output is experimental. Verify results against a reference before production use.
mdinterface.io.gromacswriter.write_gromacs_itp(specie, filename=None, *, include_atomtypes=True)
¶
Write a GROMACS include topology (.itp) file for a Specie.
.. warning:: GROMACS output is experimental and assumes harmonic bonds and angles, four-term OPLS proper torsions, CVFF impropers, geometric LJ mixing, and 0.5 LJ/Coulomb 1-4 scaling. Constraints are not generated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
specie
|
Specie
|
The molecular species to write. |
required |
filename
|
str
|
Output filename. Defaults to |
None
|
include_atomtypes
|
bool
|
Include atom-type definitions. For multi-species systems, set False
and pass the species to :func: |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If parameters are incomplete, conflicting, or unsupported. |
Source code in mdinterface/io/gromacswriter.py
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 | |
mdinterface.io.gromacswriter.write_gromacs_top(universe, itp_files, filename='system.top', system_name='MD System', *, species=None)
¶
Write a GROMACS system topology (.top) file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
universe
|
Universe
|
The assembled system (after SimCell.build()). Used to determine
molecule counts from |
required |
itp_files
|
list of str
|
Basenames of the per-species ITP files to |
required |
filename
|
str
|
Output filename. Default |
'system.top'
|
system_name
|
str
|
Title written in the |
'MD System'
|
species
|
sequence of Specie
|
Species whose atom types are written before the molecule includes.
These ITP files must be written with |
None
|
Source code in mdinterface/io/gromacswriter.py
Logging utilities¶
mdinterface.utils.logger.set_verbosity(level)
¶
Set the log level for the entire mdinterface package.
A single StreamHandler is attached to the mdinterface root logger
(at most once). All child loggers (mdinterface.build.builder,
mdinterface.io.read, etc.) propagate to it automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
bool, int, or str
|
Small integers map to a simple verbosity scale:
Integers >= 10 are passed directly as Python logging level constants
(e.g. |
required |
Source code in mdinterface/utils/logger.py
mdinterface.utils.logger.log_header(log, title, level=logging.INFO)
¶
Emit a fixed-width section header via log, preceded by a blank line.
The title is left-anchored after === and = fills the rest to
:data:_HEADER_WIDTH characters, so headers align regardless of title
length.
Example
::
from mdinterface.utils.logger import log_header
log_header(logger, "Build")
# [mdi] INFO |
# [mdi] INFO | === Build ================================
Source code in mdinterface/utils/logger.py
mdinterface.utils.logger.log_subheader(log, title, level=logging.INFO)
¶
Emit a fixed-width sub-section header via log.
Same width and left-anchor style as :func:log_header but uses -
as the fill character to indicate a lower level of hierarchy.
Example
::
log_subheader(logger, "Layer [1/4]")
# [mdi] INFO | -- Layer [1/4] ----------------------------
Source code in mdinterface/utils/logger.py
mdinterface.utils.logger.log_banner(log, *lines, level=logging.INFO)
¶
Emit a prominent multi-line banner with = borders.
Each line is centred within :data:_HEADER_WIDTH characters. Intended
for the top-level startup message of a major component (e.g. SimCell).
Example
::
log_banner(logger, "mdinterface :: SimCell", "version 1.5.0")
# [mdi] INFO | ============================================
# [mdi] INFO | mdinterface :: SimCell
# [mdi] INFO | version 1.5.0
# [mdi] INFO | ============================================