mchem
Core
CLI entry point: convert PDB to SQLite DB, solvate PDB, etc.
System of force terms and particles; load/save from SQLite DB.
- class mchem.system.Box(a: float, b: float, c: float, alpha: float, beta: float, gamma: float)[source]
Bases:
objectPeriodic box dimensions from PDB CRYST1: cell lengths a, b, c (Angstroms) and angles alpha, beta, gamma (degrees).
- mchem.system.register_term_class(cls)[source]
Register a custom term dataclass so it can be deserialized from a database file. Call this before loading a
.dbthat contains the class.
- class mchem.system.System(path: PathLike | None = None)[source]
Bases:
objectContainer for force-field terms and metadata, backed by SQLite.
Terms are stored by table name (e.g.
Particle,AmoebaBond). Metadata is stored in a separatemetatable. Useregister_term_class()to register custom term dataclasses before loading a DB that contains them.- __init__(path: PathLike | None = None)[source]
Create an empty system or load from an existing SQLite DB.
- Parameters:
path (os.PathLike, optional) – If given, path to SQLite file to load; otherwise an empty system.
- property data
Mapping of table name to
TermListof terms.
- property meta
Mapping of metadata keys to values (e.g. name, units).
- addTerm(term, name: str | None = None)[source]
Append a single term; use its class name as table name if name is not given.
- addMeta(key: str, value: Any)[source]
Set a metadata key (hyphens in key are replaced with underscores).
Residue templates (atoms and bonds) loaded from XML; used for topology matching.
- class mchem.template.ResidueTemplate(name: str, atoms: Dict[str, Dict[str, Any]], bonds: List[Dict[str, Any]], altNames: List[str] = [])[source]
Bases:
objectTemplate for a residue: atom names (with alternates) and bond list for matching.
- __init__(name: str, atoms: Dict[str, Dict[str, Any]], bonds: List[Dict[str, Any]], altNames: List[str] = [])[source]
- classmethod fromXMLData(data: Element)[source]
Build a
ResidueTemplatefrom an XMLResidueelement (name, Atom, Bond children).
- mchem.template.loadTemplateDefinitions(fname: PathLike)[source]
Load residue templates from an XML file and add them to
TEMPLATES.- Parameters:
fname (os.PathLike) – Path to XML file containing
Residueelements.
Molecular topology: residues, atoms, bonds, and connectivity.
- class mchem.topology.Residue(name: str, number: int, chain: str = 'A', insertionCode: str = '')[source]
Bases:
objectA residue (e.g. amino acid) containing atoms and optional link to a
Topology.- property topology
- property numAtoms
- property atoms
- matchTemplate(template: ResidueTemplate, stdResidueName: bool = True)[source]
Match this residue to a template: align atom names (including alternates) and add template bonds to topology.
- Parameters:
template (ResidueTemplate) – Template to match (atom names and bonds).
stdResidueName (bool, optional) – If True, set residue name to template name.
- Returns:
True if match succeeded.
- Return type:
- class mchem.topology.Atom(name: str, element: str)[source]
Bases:
objectAn atom with element, position, optional residue/topology, bonds, and force-field type/class.
- property polarizationGroup
- property atomType
- property atomClass
- property parametrized
- property residue
- property topology
- property bonds
- property pathsToBondedAtoms
- property bondedAtoms
- class mchem.topology.Bond(atom1: Atom, atom2: Atom, order: float)[source]
Bases:
objectA bond between two atoms with a bond order.
- class mchem.topology.BondedAtoms(atoms: List[Atom])[source]
Bases:
objectOrdered list of bonded atoms, with hash/equality invariant under reversal (for undirected paths).
- class mchem.topology.Topology(name: str, maxConnect: int = 5)[source]
Bases:
objectMolecular topology: list of residues, bonds, and connectivity up to
_maxConnectbonds.- property editable
- property numResidues
- property numAtoms
- property numBonds
- property bonds
- property connTable
- property bondedAtoms
Solvation: add water and ions to a solute in a periodic box.
Uses Packmol as the external placement engine and computes box dimensions
following OpenMM’s openmm.app.Modeller.addSolvent() conventions.
- mchem.solvate.BoxShape
Allowed periodic box shapes.
alias of
Literal[‘cube’, ‘dodecahedron’, ‘octahedron’]
- mchem.solvate.solvate(topology: Topology, positions: ndarray, *, box_shape: Literal['cube', 'dodecahedron', 'octahedron'] = 'cube', buffer: float = 10.0, neutralize: bool = True, ionic_strength: float = 0.0, positive_ion: str = 'Na+', negative_ion: str = 'Cl-') Tuple[Topology, ndarray, Tuple[ndarray, ndarray, ndarray]][source]
Solvate a solute with water and optional ions in a periodic box.
- Parameters:
topology (Topology) – Solute topology (no solvent).
positions (np.ndarray) – Atom positions, shape
(N, 3), in Angstroms.box_shape (BoxShape, optional) – Periodic box shape. Default is
"cube".buffer (float, optional) – Minimum padding in Angstroms between solute and box edge. Default is
10.0.neutralize (bool, optional) – If True, add counterions to neutralize the system. Default is True.
ionic_strength (float, optional) – Target ionic strength in mol/L. Default is
0.0.positive_ion (str, optional) – Positive ion type (e.g.
"Na+"). Default is"Na+".negative_ion (str, optional) – Negative ion type (e.g.
"Cl-"). Default is"Cl-".
- Returns:
(topology, positions, box_vectors)where box_vectors is a tuple of threenp.ndarrayvectors.- Return type:
- Raises:
ValueError – If an unsupported ion type is given.
RuntimeError – If Packmol fails.
Trajectory conversion utilities (an M-Chem analogue of gmx trjconv).
This module reads a topology (currently the SQLite .db format) together with
an M-Chem HDF5 (QArchive) trajectory and writes selected frames to a molecular
structure/trajectory file (currently PDB).
The design is intentionally modular so that additional topology formats
(e.g. PDB), trajectory formats, and output formats (e.g. XTC) can be added by
implementing the relevant abstract base class and registering it, without
changing the trjconv() orchestrator.
Frame indexing
Frames use the trajectory’s native 1-based numbering (matching the HDF5
time_step groups). A frame index of -1 (or None) selects the last
frame.
- class mchem.trjconv.AtomInfo(idx: int, name: str, element: str, resnum: int, resname: str, chain: str = 'A')[source]
Bases:
objectMinimal per-atom metadata required to write a structure record.
- Parameters:
- class mchem.trjconv.Frame(index: int, coordinates: ndarray, box: Tuple[float, float, float] | None = None, time: float | None = None)[source]
Bases:
objectA single trajectory frame.
- Parameters:
index (int) – Native (1-based) frame index within the trajectory.
coordinates (numpy.ndarray) – Cartesian coordinates in Angstroms, shape
(natoms, 3).box (tuple of float, optional) – Orthorhombic cell lengths
(a, b, c)in Angstroms, or None.time (float, optional) – Simulation time in picoseconds.
- class mchem.trjconv.TopologyProvider[source]
Bases:
ABCAbstract source of per-atom metadata for writing structure records.
Subclasses expose an ordered list of
AtomInfowhose order matches the atom/column order of the trajectory being converted.
- class mchem.trjconv.DBTopologyProvider(path: PathLike)[source]
Bases:
TopologyProviderTopology provider backed by an M-Chem SQLite
.dbfile.Reads the
Particleterm table directly (see db_format), which keeps the provider lightweight and robust to auxiliary tables that are not needed to write structure records.- Parameters:
path (os.PathLike) – Path to the
.dbtopology file.
- class mchem.trjconv.TrajectoryReader[source]
Bases:
ABCAbstract random-access reader over trajectory frames.
Frames are addressed by native 1-based index. Iterating a reader yields
Frameobjects in ascending frame order.
- class mchem.trjconv.HDF5TrajectoryReader(path: PathLike, job_id: int | None = None)[source]
Bases:
TrajectoryReaderReader for M-Chem HDF5 (QArchive) trajectories.
The expected layout is:
job/{job_id}/molecular_dynamics/ natoms time_step/{frame}/ coordinates [3, natoms] (Angstrom) box [3] (Angstrom) time scalar (ps)
Coordinates are stored column-major as
(3, natoms)and are transposed to(natoms, 3)on read.- Parameters:
path (os.PathLike) – Path to the
.h5trajectory file.job_id (int, optional) – Job group to read. If None, the single available job is auto-detected.
- class mchem.trjconv.TrajectoryWriter[source]
Bases:
ABCAbstract writer for one or more frames to an output file.
Use as a context manager so resources are flushed and closed. Multiple calls to
write_frame()append successive models/frames.
- class mchem.trjconv.PDBTrajectoryWriter(path: PathLike)[source]
Bases:
TrajectoryWriterWrite frames as PDB records.
A single frame is written as a plain
ATOM/HETATMblock preceded by aCRYST1record (when box information is available). When more than one frame is written, each is wrapped inMODEL/ENDMDLrecords, laying the groundwork for future multi-frame output.- Parameters:
path (os.PathLike) – Output PDB path.
- mchem.trjconv.trjconv(topology_path: PathLike, trajectory_path: PathLike, output_path: PathLike, frame: int | None = None) Frame[source]
Convert an M-Chem trajectory frame to a structure file.
Picks a topology provider, trajectory reader, and output writer based on file extensions, extracts the requested frame, and writes it out.
- Parameters:
topology_path (os.PathLike) – Topology file (currently
.db).trajectory_path (os.PathLike) – M-Chem HDF5 trajectory (
.h5/.hdf5).output_path (os.PathLike) – Output structure file (currently
.pdb).frame (int, optional) – Native 1-based frame index.
Noneor-1selects the last frame.
- Returns:
The frame that was written (with resolved index).
- Return type:
- Raises:
ValueError – If a format is unsupported or the topology and trajectory atom counts do not match.
IndexError – If the requested frame does not exist.
Physical constants and unit conversion factors for energy and length.
Periodic table data: element symbol, mass, and name.
Force field
Force field XML loading and term generation (see ForceField, Generator).
Force field definition from XML: atom types, residues, and force generators.
- mchem.forcefield.base.str2bool(string)[source]
Convert string to bool (True/False, case-insensitive).
- mchem.forcefield.base.xmlele2str(xmlele: Element)[source]
Serialize XML element to string (unicode, stripped).
- class mchem.forcefield.base.AtomType(name: str, atomClass: str)[source]
Bases:
objectForce-field atom type with name and class.
- class mchem.forcefield.base.ForceField(*files)[source]
Bases:
objectLoad and apply a force field from one or more XML files.
Parses AtomTypes, Residues, and force elements (e.g. AmoebaBondForce); uses
Parsersto create generators that produce terms for aTopology.- __init__(*files)[source]
Load force field from one or more XML files.
- Parameters:
*files (str or os.PathLike) – XML paths; resolved via
processFileNames()if not found.
- processFileNames(files)[source]
Resolve file paths; search next to this module if not found. Returns list of paths.
- property generators
List of force generators (one per force type from XML).
- getGeneratorWithClass(generatorClass)[source]
Return the first generator that is an instance of generatorClass, or None.
- addGeneratorWithClass(generatorClass)[source]
Get or create a generator of the given class and return it.
- addAtomType(atomTypeElement: Element)[source]
Register an atom type from an XML
Typeelement (name, class).
- loadAtomTypeDefs()[source]
Map residue atom names to atom types from Residues section (templates must exist).
- assignAtomTypes(topology: Topology)[source]
Set atom type and class on each atom from residue templates.
- findAtomTypes(element: Element, numAtoms: int)[source]
Resolve type/class attributes to list of atom type name tuples (supports wildcards).
- createSystem(topology: Topology, **kwargs)[source]
Build a
Systemwith particles and all generator terms for the given topology.
- class mchem.forcefield.base.Generator(ff: ForceField, paramFields: List[str] = [], raiseError: bool = True)[source]
Bases:
objectBase class for a force generator: holds parameters keyed by atom type/SMIRKS and creates terms for a topology.
Force generators: create bonded/nonbonded terms from XML and topology.
- class mchem.forcefield.generators.HarmonicBondGenerator(ff)[source]
Bases:
GeneratorGenerator for Harmonic Bonds
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.HarmonicAngleGenerator(ff)[source]
Bases:
GeneratorGenerator for Harmonic Angles
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmoebaBondGenerator(ff)[source]
Bases:
GeneratorGenerator for AMOEBA bond terms (quartic) from AmoebaBondForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmoebaAngleGenerator(ff)[source]
Bases:
GeneratorGenerator for AMOEBA angle and in-plane angle terms from AmoebaAngleForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmoebaUreyBradleyGenerator(ff)[source]
Bases:
GeneratorGenerator for AMOEBA Urey-Bradley terms from AmoebaUreyBradleyForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.MultipoleGenerator(ff)[source]
Bases:
GeneratorGenerator for atomic multipoles from AmoebaMultipoleForce / MBUCBMultipoleForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.IsotropicPolarizationGenerator(ff)[source]
Bases:
GeneratorGenerator for isotropic polarizability terms from Polarize elements.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmberNonbondedGenerator(ff)[source]
Bases:
Generator- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmoebaVdwGenerator(ff)[source]
Bases:
GeneratorGenerator for AMOEBA buffered 14-7 VdW terms from AmoebaVdwForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmoebaStretchBendGenerator(ff)[source]
Bases:
GeneratorGenerator for AMOEBA stretch-bend coupling from AmoebaStretchBendForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmoebaOutOfPlaneBendGenerator(ff)[source]
Bases:
GeneratorGenerator for AMOEBA out-of-plane bend terms from AmoebaOutOfPlaneBendForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmoebaPiTorsionGenerator(ff)[source]
Bases:
GeneratorGenerator for AMOEBA pi-torsion terms from AmoebaPiTorsionForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.PeriodicTorsionGenerator(ff)[source]
Bases:
GeneratorGenerator for periodic proper torsions from PeriodicTorsionForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AmoebaTorsionTorsionGenerator(ff)[source]
Bases:
GeneratorGenerator for AMOEBA torsion-torsion (5-atom) terms and grids from AmoebaTorsionTorsionForce XML.
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.AnisotropicPolarizationGenerator(ff)[source]
Bases:
GeneratorGenerator for anisotropic polarizability from Polarize elements (MBUCB).
- static parseElement(element: Element, ff: ForceField)[source]
- class mchem.forcefield.generators.MBUCBChargePenetrationGenerator(ff)[source]
Bases:
GeneratorGenerator for MBUCB charge-penetration terms from ChargePenetration elements.
- static parseElement(element: Element, ff: ForceField)[source]
Terms
Force term dataclasses and TermList (bonded, nonbonded).
Base container for force-term lists keyed by term class.
- class mchem.terms.base.TermList(cls)[source]
Bases:
listList of force terms restricted to a single dataclass type.
Used by
mchem.system.Systemto store terms per table (e.g.AmoebaBond).- __init__(cls)[source]
- Parameters:
cls (type) – Dataclass type; only instances of this type can be appended.
- property cls
Term dataclass type for this list.
Bonded force terms: bonds, angles, Urey-Bradley, torsions, CMAP, AMOEBA-specific.
- class mchem.terms.bonded.HarmonicBond(p0: int, p1: int, b0: float, kb: float, paramIdx: int = -1)[source]
Bases:
objectClass for a bond with normal harmonic potential
- class mchem.terms.bonded.AmoebaBond(p0: int, p1: int, b0: float, kb: float, cubic: float, quartic: float, paramIdx: int = -1)[source]
Bases:
objectClass for a bond in AMOEBA force field, i.e. up to quartic polynomials
- class mchem.terms.bonded.HarmonicAngle(p0: int, p1: int, p2: int, th0: float, kth: float, paramIdx: int = -1)[source]
Bases:
objectClass for an angle with harmonic potential
- class mchem.terms.bonded.AmoebaAngle(p0: int, p1: int, p2: int, th0: float, kth: float, cubic: float, quartic: float, pentic: float, sextic: float, paramIdx: int = -1)[source]
Bases:
objectClass for an angle in AMOEBA force field (up to sextic polynomials)
- class mchem.terms.bonded.AmoebaAngleInPlane(p0: int, p1: int, p2: int, p3: int, th0: float, kth: float, cubic: float, quartic: float, pentic: float, sextic: float, paramIdx: int = -1)[source]
Bases:
objectClass for an in-plane angle in AMOEBA force field (up to sextic polynomials)
- class mchem.terms.bonded.AmoebaStretchBend(p0: int, p1: int, p2: int, th0: float, b01: float, b02: float, kb1: float, kb2: float, paramIdx: int = -1)[source]
Bases:
objectClass for stretch-bend coupling term in AMOEBA force field
- class mchem.terms.bonded.AmoebaUreyBradley(p0: int, p1: int, p2: int, r0: float, fc: float, paramIdx: int = -1)[source]
Bases:
objectClass for Urey-Bradley term used in AMOEBA force field
- class mchem.terms.bonded.AmoebaOutOfPlaneBend(p0: int, p1: int, p2: int, p3: int, fc: float, paramIdx: int = -1)[source]
Bases:
objectClass for out-of-plane bending term in AMOEBA force field
- class mchem.terms.bonded.PeriodicTorsion(p0: int, p1: int, p2: int, p3: int, phase1: float, phase2: float, phase3: float, phase4: float, phase5: float, phase6: float, k1: float, k2: float, k3: float, k4: float, k5: float, k6: float, paramIdx: int = -1)[source]
Bases:
objectPeriodic torsion (dihedral) term with up to six Fourier components.
- class mchem.terms.bonded.AmoebaStretchTorsion(p0: int, p1: int, p2: int, p3: int, k11: float, k12: float, k13: float, k21: float, k22: float, k23: float, k31: float, k32: float, k33: float, b01: float, b02: float, b03: float, phi01: float, phi02: float, phi03: float)[source]
Bases:
objectClass for AMOEBA stretch-torsion coupling term
- class mchem.terms.bonded.AmoebaAngleTorsion(p0: int, p1: int, p2: int, p3: int, k11: float, k12: float, k13: float, k21: float, k22: float, k23: float, th01: float, th02: float, phi01: float, phi02: float, phi03: float, paramIdx: int = -1)[source]
Bases:
objectClass for AMOEBA angle-torsion coupling term
- class mchem.terms.bonded.AmoebaPiTorsion(p0: int, p1: int, p2: int, p3: int, p4: int, p5: int, k: float, paramIdx: int = -1)[source]
Bases:
objectClass for pi-torsion term in Amoeba
- class mchem.terms.bonded.CMAPTable(phi: float, psi: float, ene: float, paramIdx: int = -1)[source]
Bases:
objectClass for a CMAP tabulated torsion-torsion coupling term
- class mchem.terms.bonded.CMAP(cmap: int, p0: int, p1: int, p2: int, p3: int, p4: int, p5: int, p6: int, p7: int)[source]
Bases:
objectClass for CMAP torsion-torsion coupling term
- class mchem.terms.bonded.AmoebaTorsionTorsionGrid(angle1: float, angle2: float, f: float, gridIdx: int)[source]
Bases:
objectClass for an AMOEBA torsion-torsion 2D energy grid point
- class mchem.terms.bonded.AmoebaTorsionTorsion(p0: int, p1: int, p2: int, p3: int, p4: int, gridIdx: int, nx: int, ny: int)[source]
Bases:
objectClass for an AMOEBA torsion-torsion coupling term (5-atom chain)
Non-bonded terms: particles, VdW, multipoles, polarization, MBUCB.
- class mchem.terms.nonbonded.MultipoleAxisType(value)[source]
Bases:
EnumAxis convention for multipole frame (ZThenX, Bisector, ZOnly, etc.).
- ZThenX = 0
- Bisector = 1
- ZBisect = 2
- ThreeFold = 3
- ZOnly = 4
- NoAxisType = 5
- LastAxisTypeIndex = 6
- class mchem.terms.nonbonded.Particle(idx: int, name: str, element: str, mass: float, resnum: int, resname: str, xx: float, xy: float, xz: float, vx: float = 0.0, vy: float = 0.0, vz: float = 0.0)[source]
Bases:
objectSingle particle: index, name, element, mass, residue info, position, optional velocity.
- class mchem.terms.nonbonded.AmoebaVdw147(idx: int, epsilon: float, sigma: float, parentIdx: int = -1, reduction: float = 1.0, paramIdx: int = -1)[source]
Bases:
objectAMOEBA buffered 14-7 VdW parameters (epsilon, sigma, reduction, optional parent).
- class mchem.terms.nonbonded.AmberNonbonded(idx: int, charge: float, epsilon: float, sigma: float, paramIdx: int = -1)[source]
Bases:
objectAMBER Nonbonded parameters
- class mchem.terms.nonbonded.Multipole(idx: int, c0: float, dx: float, dy: float, dz: float, qxx: float, qxy: float, qxz: float, qyy: float, qyz: float, qzz: float, axistype: int, kz: int = -1, kx: int = -1, ky: int = -1, paramIdx: int = -1)[source]
Bases:
objectAtomic multipole (charge, dipole, quadrupole) and axis type / frame indices.
- class mchem.terms.nonbonded.IsotropicPolarization(idx: int, alpha: float, thole: float, grp: list, paramIdx: int = -1)[source]
Bases:
objectIsotropic polarizability (alpha, thole) and polarization group indices.
- class mchem.terms.nonbonded.AnisotropicPolarization(idx: int, alphaxx: float, alphaxy: float, alphaxz: float, alphayy: float, alphayz: float, alphazz: float, thole: float, grp: list = <factory>, paramIdx: int = -1)[source]
Bases:
objectAnisotropic polarizability tensor (alpha_xx, alpha_xy, …) and thole/group.
- class mchem.terms.nonbonded.MBUCBChargePenetration(idx: int, z: float, alpha: float, beta: float, paramIdx: int = -1)[source]
Bases:
objectMBUCB charge-penetration correction parameters (z, alpha, beta).
File formats
File format loaders (e.g. PDB) that produce mchem.topology.Topology.
PDB file I/O: read/write Topology from/to ATOM/HETATM records.
- mchem.fileformats.pdb.read_pdb_box(fname: PathLike) Tuple[float, float, float, float, float, float] | None[source]
Read periodic box dimensions from the first CRYST1 record in a PDB file.
- mchem.fileformats.pdb.load_pdb(fname: PathLike) Topology[source]
Load a topology from a PDB file (ATOM/HETATM), match residue templates, and return editable topology.
- Parameters:
fname (os.PathLike) – Path to the PDB file.
- Returns:
Topology with residues and atoms; templates are matched so bonds and standard names are set.
- Return type:
- mchem.fileformats.pdb.format_cryst1_record(a: float, b: float, c: float, alpha: float, beta: float, gamma: float) str[source]
Format a PDB
CRYST1record from cell lengths and angles.- Parameters:
- Returns:
A single
CRYST1line terminated by a newline.- Return type:
- mchem.fileformats.pdb.format_atom_record(serial: int, name: str, resname: str, chain: str, resnum: int, x: float, y: float, z: float, symbol: str, hetatm: bool | None = None) str[source]
Format a single PDB
ATOM/HETATMrecord.- Parameters:
serial (int) – Atom serial number (1-based).
name (str) – Atom name.
resname (str) – Residue name.
chain (str) – Chain identifier (single character).
resnum (int) – Residue sequence number.
x (float) – Cartesian coordinates in Angstroms.
y (float) – Cartesian coordinates in Angstroms.
z (float) – Cartesian coordinates in Angstroms.
symbol (str) – Element symbol.
hetatm (bool, optional) – Force
HETATM(True) orATOM(False). If None, decide from_HETATM_RESIDUESbased onresname.
- Returns:
A single record line terminated by a newline.
- Return type:
- mchem.fileformats.pdb.write_pdb(fname: PathLike, topology: Topology, positions: ndarray, box_vectors: Tuple[ndarray, ndarray, ndarray] | None = None) None[source]
Write a PDB file from a topology and positions.
- Parameters:
fname (os.PathLike) – Output PDB file path.
topology (Topology) – Molecular topology.
positions (np.ndarray) – Atom positions, shape
(N, 3), in Angstroms.box_vectors (tuple of np.ndarray, optional) – Three box vectors
(v1, v2, v3). If provided, aCRYST1record is written at the top of the file.