Configuration Module
Configuration schema for PolyzyMD simulations.
This module defines Pydantic models for all configuration sections, providing validation, type safety, and YAML/JSON serialization support.
- class polyzymd.config.schema.ChargeMethod(value)[source]
-
Supported charge assignment methods for small molecules.
- NAGL = 'nagl'
- ESPALOMA = 'espaloma'
- AM1BCC = 'am1bcc'
- class polyzymd.config.schema.WaterModel(value)[source]
-
Supported water models.
- TIP3P = 'tip3p'
- SPCE = 'spce'
- TIP4P = 'tip4p'
- TIP4PEW = 'tip4pew'
- OPC = 'opc'
- class polyzymd.config.schema.BoxShape(value)[source]
-
Supported simulation box shapes.
- CUBE = 'cube'
- RHOMBIC_DODECAHEDRON = 'rhombic_dodecahedron'
- TRUNCATED_OCTAHEDRON = 'truncated_octahedron'
- class polyzymd.config.schema.Ensemble(value)[source]
-
Thermodynamic ensemble types.
- NVT = 'NVT'
- NPT = 'NPT'
- NVE = 'NVE'
- class polyzymd.config.schema.ThermostatType(value)[source]
-
Supported thermostat types.
- LANGEVIN_MIDDLE = 'LangevinMiddle'
- LANGEVIN = 'Langevin'
- ANDERSEN = 'Andersen'
- NOSE_HOOVER = 'NoseHoover'
- class polyzymd.config.schema.BarostatType(value)[source]
-
Supported barostat types.
- MONTE_CARLO = 'MC'
- MONTE_CARLO_ANISOTROPIC = 'MCA'
- class polyzymd.config.schema.RestraintType(value)[source]
-
Types of restraints that can be applied.
- FLAT_BOTTOM = 'flat_bottom'
- HARMONIC = 'harmonic'
- UPPER_WALL = 'upper_wall'
- LOWER_WALL = 'lower_wall'
- class polyzymd.config.schema.EnzymeConfig(*, name, pdb_path, description=None)[source]
Bases:
BaseModelConfiguration for the enzyme/protein component.
- pdb_path
Path to the PDB file containing the enzyme structure
- Type:
Path
- pdb_path: Path
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.SubstrateConfig(*, name, sdf_path, conformer_index=0, charge_method=ChargeMethod.NAGL, residue_name='LIG')[source]
Bases:
BaseModelConfiguration for the docked substrate/ligand.
- sdf_path
Path to SDF file with docked conformers
- Type:
Path
- charge_method
Method for assigning partial charges
- Type:
- sdf_path: Path
- charge_method: ChargeMethod
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.PolymerPackingConfig(*, padding=2.0, tolerance=2.0, movebadrandom=False, box_vectors=None)[source]
Bases:
BaseModelSettings for packing polymers around the solute.
Controls the box size and PACKMOL behavior when packing polymers around the protein-ligand complex.
- padding
Box padding around the solute in nanometers. Larger values give polymers more room and can speed up PACKMOL convergence.
- Type:
- movebadrandom
When
True, pass themovebadrandomkeyword to PACKMOL. This places badly-packed molecules at random positions in the box rather than near well-packed neighbours, which improves convergence for dense or heterogeneous systems (many unique chain types). Has no effect when only a single chain type is present. Default isFalse(PACKMOL default behaviour is preserved).- Type:
- box_vectors
Optional explicit box dimensions
[Lx, Ly, Lz]in nanometers. When set, overrides the auto-computed bounding box plus padding. The protein is centered at the midpoint of the box. Default isNone(auto-compute from solute bounding box + padding).
Example
>>> PolymerPackingConfig(padding=2.5, movebadrandom=True) >>> PolymerPackingConfig(box_vectors=[8.0, 10.0, 12.0])
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.MonomerSpec(*, label, probability, name=None, smiles=None, residue_name=None)[source]
Bases:
BaseModelSpecification for a single monomer type in a co-polymer.
For dynamic polymer generation, provide the raw (unactivated) monomer SMILES. The system will run initiation reactions to create the active fragments.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.PolymerGenerationMode(value)[source]
-
Mode for polymer generation.
- CACHED = 'cached'
- DYNAMIC = 'dynamic'
- class polyzymd.config.schema.ReactionConfig(*, initiation, polymerization, termination)[source]
Bases:
BaseModelPaths to reaction templates for ATRP polymer generation.
These .rxn files define the chemical transformations used to create polymer fragments from raw monomer SMILES. For ATRP, this includes: - Initiation: Activates the vinyl group (e.g., chlorination) - Polymerization: Creates chain-extending fragments - Termination: Restores the alkene for chain ends
You can use “default” as a special value to use the bundled ATRP methacrylate reaction templates that ship with PolyzyMD.
Example
- reactions:
initiation: “default” polymerization: “default” termination: “default”
- initiation
Path to the initiation reaction template (.rxn) or “default”
- Type:
Path
- polymerization
Path to the polymerization reaction template (.rxn) or “default”
- Type:
Path
- termination
Path to the termination reaction template (.rxn) or “default”
- Type:
Path
- initiation: Path
- polymerization: Path
- termination: Path
- classmethod resolve_default_paths(v, info)[source]
Resolve ‘default’ to bundled ATRP reaction paths.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.PolymerConfig(*, enabled=True, generation_mode=PolymerGenerationMode.CACHED, type_prefix, monomers, length, count, sdf_directory=None, reactions=None, charger=ChargeMethod.NAGL, max_retries=10, cache_directory=PosixPath('.polymer_cache'), packing=<factory>, random_seed=None)[source]
Bases:
BaseModelConfiguration for polymer components.
Supports two generation modes: - “cached”: Load pre-built polymer SDF files from sdf_directory (legacy) - “dynamic”: Generate polymers on-the-fly using Polymerist from SMILES
For dynamic mode, you must provide: - SMILES for each monomer in monomers[].smiles - Reaction templates in the reactions field
- generation_mode
“cached” for pre-built SDFs, “dynamic” for on-the-fly generation
- Type:
- monomers
List of monomer specifications with probabilities (and SMILES for dynamic)
- Type:
List[MonomerSpec]
- sdf_directory
Path to pre-built polymer SDF files (for cached mode)
- Type:
Optional[Path]
- reactions
Reaction templates for ATRP (required for dynamic mode)
- Type:
Optional[ReactionConfig]
- charger
Charge assignment method for generated polymers
- Type:
- cache_directory
Directory for caching generated polymers and fragments
- Type:
Path
- packing
Settings for packing polymers around the solute
- Type:
- generation_mode: PolymerGenerationMode
- monomers: List[MonomerSpec]
- reactions: ReactionConfig | None
- charger: ChargeMethod
- cache_directory: Path
- packing: PolymerPackingConfig
- validate_generation_mode_requirements()[source]
Validate that required fields are present for the selected generation mode.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.CoSolventSpec(*, name, smiles=None, volume_fraction=None, concentration=None, density=None, residue_name=None)[source]
Bases:
BaseModelSpecification for a co-solvent component.
You must specify EITHER volume_fraction OR concentration, not both.
For co-solvents in the built-in library (dmso, dmf, urea, ethanol, etc.), you can omit the smiles and density fields - they will be looked up automatically.
- Example (library co-solvent with volume fraction):
>>> CoSolventSpec(name="dmso", volume_fraction=0.30)
- Example (library co-solvent with concentration):
>>> CoSolventSpec(name="urea", concentration=2.0)
- Example (custom co-solvent):
>>> CoSolventSpec( ... name="my_solvent", ... smiles="CCOC(=O)C", ... density=0.902, ... volume_fraction=0.15 ... )
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.PrimarySolventConfig(*, type='water', model=WaterModel.TIP3P)[source]
Bases:
BaseModelConfiguration for the primary solvent (usually water).
- model
Water model to use (if type is “water”)
- Type:
- model: WaterModel
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.IonConfig(*, neutralize=True, nacl_concentration=0.1, kcl_concentration=0.0, mgcl2_concentration=0.0)[source]
Bases:
BaseModelConfiguration for ions in the solvent.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.BoxConfig(*, padding=1.2, shape=BoxShape.RHOMBIC_DODECAHEDRON, target_density=1.0, tolerance=2.0)[source]
Bases:
BaseModelConfiguration for the simulation box.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.SolventConfig(*, primary=<factory>, co_solvents=<factory>, ions=<factory>, box=<factory>)[source]
Bases:
BaseModelComplete solvent configuration.
- primary
Primary solvent settings
- Type:
- co_solvents
List of co-solvent specifications
- Type:
List[CoSolventSpec]
- primary: PrimarySolventConfig
- co_solvents: List[CoSolventSpec]
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.AtomSelectionConfig(*, selection, description=None)[source]
Bases:
BaseModelConfiguration for selecting atoms for restraints.
Uses MDAnalysis-compatible selection syntax for flexibility.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.RestraintConfig(*, type, name, atom1, atom2, distance, force_constant=10000.0, enabled=True)[source]
Bases:
BaseModelConfiguration for a single restraint.
- type
Type of restraint (flat_bottom, harmonic, etc.)
- Type:
- atom1
First atom selection
- Type:
- atom2
Second atom selection
- Type:
- type: RestraintType
- atom1: AtomSelectionConfig
- atom2: AtomSelectionConfig
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.ThermodynamicsConfig(*, temperature, pressure=1.0)[source]
Bases:
BaseModelThermodynamic conditions for the simulation.
- salt_concentration
Ionic strength in mol/L (deprecated, use solvent.ions)
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.SimulationPhaseConfig(*, ensemble, duration, samples, time_step=2.0, thermostat=ThermostatType.LANGEVIN_MIDDLE, thermostat_timescale=1.0, barostat=None, barostat_frequency=25, checkpoint_interval=60.0)[source]
Bases:
BaseModelConfiguration for a single simulation phase (equilibration or production).
- thermostat
Thermostat type
- Type:
- barostat
Barostat type (for NPT)
- Type:
Optional[BarostatType]
- checkpoint_interval
Wall-time interval (seconds) between restart checkpoints for preemption resilience
- Type:
- thermostat: ThermostatType
- barostat: BarostatType | None
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.PositionRestraintConfig(*, group, force_constant=4184.0)[source]
Bases:
BaseModelConfiguration for positional restraints on an atom group.
Position restraints apply a harmonic potential to keep atoms near their initial coordinates. This is commonly used during equilibration to prevent large structural changes while the system relaxes.
- classmethod validate_group_name(v)[source]
Validate that the group name is a recognized predefined group.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.EquilibrationStageConfig(*, name, duration, samples=100, ensemble=Ensemble.NVT, temperature=None, temperature_start=None, temperature_end=None, temperature_increment=1.0, temperature_interval=1200.0, position_restraints=<factory>, time_step=None, thermostat=None, thermostat_timescale=None, barostat=None, barostat_frequency=None)[source]
Bases:
BaseModelConfiguration for a single equilibration stage.
Supports two temperature modes: 1. Constant temperature: Set ‘temperature’ field 2. Temperature ramping (simulated annealing): Set ‘temperature_start’ and
‘temperature_end’ fields
Position restraints can be applied to hold specific atom groups in place during the stage.
- position_restraints
List of position restraints for this stage
- Type:
List[PositionRestraintConfig]
- thermostat
Optional thermostat type override
- Type:
Optional[ThermostatType]
- barostat
Optional barostat type (for NPT ensemble)
- Type:
Optional[BarostatType]
- position_restraints: List[PositionRestraintConfig]
- thermostat: ThermostatType | None
- barostat: BarostatType | None
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.SimulationPhasesConfig(*, equilibration_stages=None, production)[source]
Bases:
BaseModelConfiguration for all simulation phases.
- equilibration_stages
Multi-stage equilibration protocol
- Type:
Optional[List[EquilibrationStageConfig]]
- production
Production phase settings
- Type:
- model_config = {'extra': 'ignore'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- equilibration_stages: List[EquilibrationStageConfig] | None
- production: SimulationPhaseConfig
- classmethod warn_deprecated_segments(data)[source]
Warn if the deprecated ‘segments’ field is present and remove it.
- polyzymd.config.schema.expand_path(path)[source]
Expand environment variables and user home in a path.
Supports: - $VAR and ${VAR} syntax for environment variables - ~ for user home directory
- class polyzymd.config.schema.OutputConfig(*, projects_directory=PosixPath('.'), scratch_directory=None, naming_template='{enzyme}_{substrate}_{polymer_type}_{duration}ns_{temperature}K_run{replicate}', job_scripts_subdir='job_scripts', slurm_logs_subdir='slurm_logs', save_checkpoint=True, save_state_data=True, trajectory_format='dcd', base_directory=None)[source]
Bases:
BaseModelConfiguration for simulation output.
Supports separate directories for: - scripts/logs (projects_directory): Where job scripts and SLURM logs are written - simulation data (scratch_directory): Where trajectories, checkpoints go
This separation allows running simulations on HPC systems where code lives in long-term storage (projects) but data is written to high-performance scratch storage.
- projects_directory
Directory for scripts, configs, logs (long-term storage)
- Type:
Path
- scratch_directory
Directory for simulation output (high-performance storage)
- Type:
Optional[Path]
- Example YAML:
- output:
projects_directory: /projects/user/polyzymd scratch_directory: /scratch/alpine/user/simulations naming_template: “{enzyme}_{substrate}_{temperature}K_run{replicate}”
- projects_directory: Path
- classmethod expand_env_vars_in_paths(v)[source]
Expand environment variables and ~ in path fields.
Supports $USER, ${HOME}, ~/path, etc.
- handle_legacy_base_directory()[source]
Handle legacy base_directory field for backwards compatibility.
- property effective_scratch_directory: Path
Get the effective scratch directory (falls back to projects if not set).
- format_directory_name(enzyme, substrate, polymer_type, temperature, replicate, duration=0.0, **kwargs)[source]
Format the directory name using the template.
- Parameters:
- Returns:
Formatted directory name
- Return type:
- get_job_scripts_directory()[source]
Get the directory for job scripts.
- Returns:
Path to job scripts directory (within projects)
- Return type:
- get_slurm_logs_directory()[source]
Get the directory for SLURM log files.
- Returns:
Path to SLURM logs directory (within projects)
- Return type:
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.ForceFieldConfig(*, protein='ff14sb_off_impropers_0.0.4.offxml', small_molecule='openff-2.0.0.offxml')[source]
Bases:
BaseModelConfiguration for force field selection.
- water
Water model force field (derived from solvent config)
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class polyzymd.config.schema.SimulationConfig(*, name, description=None, enzyme, substrate=None, polymers=None, solvent=<factory>, restraints=<factory>, thermodynamics, simulation_phases, output=<factory>, force_field=<factory>)[source]
Bases:
BaseModelComplete simulation configuration.
This is the top-level configuration model that contains all settings for a PolyzyMD simulation.
- enzyme
Enzyme configuration
- Type:
- substrate
Substrate/ligand configuration
- Type:
Optional[SubstrateConfig]
- polymers
Polymer configuration (optional)
- Type:
Optional[PolymerConfig]
- solvent
Solvent and box configuration
- Type:
- restraints
List of restraint configurations
- Type:
List[RestraintConfig]
- thermodynamics
Temperature/pressure settings
- Type:
- simulation_phases
Equilibration and production settings
- Type:
- output
Output file settings
- Type:
- force_field
Force field selection
- Type:
Example
>>> config = SimulationConfig.from_yaml("simulation.yaml") >>> print(config.enzyme.name) "LipA"
- enzyme: EnzymeConfig
- substrate: SubstrateConfig | None
- polymers: PolymerConfig | None
- solvent: SolventConfig
- restraints: List[RestraintConfig]
- thermodynamics: ThermodynamicsConfig
- simulation_phases: SimulationPhasesConfig
- output: OutputConfig
- force_field: ForceFieldConfig
- classmethod from_yaml(path)[source]
Load configuration from a YAML file.
- Parameters:
- Returns:
SimulationConfig instance
- Raises:
FileNotFoundError – If file doesn’t exist
ValidationError – If configuration is invalid
- Return type:
- get_working_directory(replicate=1)[source]
Get the working directory path for a given replicate (in scratch).
This returns the path where simulation output (trajectories, checkpoints) will be written, which is in the scratch directory.
- get_projects_directory()[source]
Get the projects directory path.
This is where scripts, configs, and logs are stored.
- Returns:
Path to the projects directory
- Return type:
- discover_replicate_dirs()[source]
Auto-detect all replicate directories on disk.
Builds a glob pattern from the naming template with
replicate="*"and scans the effective scratch directory.
- to_signac_statepoint(replicate=1)[source]
Convert configuration to a Signac-compatible state point dictionary.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Loader Utilities
YAML configuration loader and saver for PolyzyMD.
This module provides functions to load and save SimulationConfig objects from/to YAML files, with support for Path objects and environment variable expansion.
- class polyzymd.config.loader.ConfigLoader(base_path)[source]
Bases:
objectCustom YAML loader with support for includes and references.
- polyzymd.config.loader.load_config(path)[source]
Load a SimulationConfig from a YAML file.
- Parameters:
- Returns:
Validated SimulationConfig instance
- Raises:
FileNotFoundError – If the config file doesn’t exist
yaml.YAMLError – If the YAML is malformed
pydantic.ValidationError – If the configuration is invalid
- Return type:
Example
>>> config = load_config("my_simulation.yaml") >>> print(config.enzyme.name) "LipA"
- polyzymd.config.loader.save_config(config, path, relative_paths=True)[source]
Save a SimulationConfig to a YAML file.
- Parameters:
config (SimulationConfig) – Configuration to save
relative_paths (bool) – Whether to convert paths to relative (default: True)
Example
>>> config = SimulationConfig(...) >>> save_config(config, "output_config.yaml")
- polyzymd.config.loader.load_config_dict(data, base_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/polyzymd/checkouts/v1.2.1/docs/source'))[source]
Create a SimulationConfig from a dictionary.
This is useful for programmatic configuration creation.
- Parameters:
- Returns:
Validated SimulationConfig instance
- Return type:
Example
>>> data = { ... "name": "test_sim", ... "enzyme": {"name": "LipA", "pdb_path": "enzyme.pdb"}, ... ... ... } >>> config = load_config_dict(data)