iphasimulator.build_pha ======================= .. py:module:: iphasimulator.build_pha .. autoapi-nested-parse:: Created on Thu Jul 2 15:15:00 2026 @author: daniel PHA polymer construction tools. This module provides the main builder class for a PHA-specific structure database. It currently supports three stages of the AmberTools-based PHA construction workflow: 1. Parameterise a PHA trimer from a SMILES string. 2. Generate head, mainchain and tail prepin files from manual prepgen definition files. 3. Build a polymer of a chosen length using tleap. The class relies on: PHAFileManager Handles directory creation and path construction. PHAResidueCodeManager Handles residue code assignment and lookup. External programs required: - OpenBabel / pybel - AmberTools: antechamber, parmchk2, prepgen, tleap Classes ------- .. autoapisummary:: iphasimulator.build_pha.PHAPolymerBuilder Module Contents --------------- .. py:class:: PHAPolymerBuilder(root_dir='structure_database') Main interface for building PHA structures. :param root_dir: Root directory of the PHA structure database. :type root_dir: str or pathlib.Path, optional .. rubric:: Notes This class coordinates chemistry-building tasks, but delegates all path handling to `PHAFileManager` and all residue-code handling to `PHAResidueCodeManager`. .. py:attribute:: paths .. py:attribute:: residue_codes .. py:method:: parameterise_trimer(PHA_type, trimer_name, trimer_smiles, monomer_smiles, forcefield='gaff2', charge_model='abcg2') Parameterise a PHA trimer using AmberTools. :param PHA_type: PHA type name, e.g. "3HB". :type PHA_type: str :param trimer_name: Name of the trimer, e.g. "P3HB_3". :type trimer_name: str :param trimer_smiles: SMILES string for the trimer. :type trimer_smiles: str :param monomer_smiles: SMILES string for the monomer unit. This is stored in the residue code database for the head, mainchain and tail components. :type monomer_smiles: str :param forcefield: Amber atom type set to use with antechamber. :type forcefield: str, optional :param charge_model: Charge model to use with antechamber. :type charge_model: str, optional :returns: Paths to the generated trimer files and residue information. :rtype: dict .. py:method:: generate_polymer_prepins(PHA_type) Generate head, mainchain and tail prepin files for a PHA type. :param PHA_type: PHA type name, e.g. "3HB". :type PHA_type: str :returns: Paths to the generated prepin files and associated residue codes. :rtype: dict .. rubric:: Notes Manual prepgen definition files must already exist in: structure_database/PHA_types//input/ For PHA_type="3HB", the expected files are: head_P3HB_3.txt mainchain_P3HB_3.txt tail_P3HB_3.txt .. py:method:: build_PHA_polymer(PHA_type, length, forcefield='gaff2') Build a PHA polymer using existing monomer prepin files. :param PHA_type: PHA type name, e.g. "3HB". :type PHA_type: str :param length: Number of repeat units in the polymer. :type length: int :param forcefield: Amber forcefield leaprc suffix. :type forcefield: str, optional :returns: Paths to generated Amber files and sequence information. :rtype: dict .. rubric:: Notes For length 10, this constructs: head + 8 mainchain units + tail Required files: hP.prepin mP.prepin tP.prepin P_3.frcmod .. py:method:: smiles_to_pdb(smiles, output_pdb) Convert a SMILES string into a 3D PDB structure. :param smiles: Input SMILES string. :type smiles: str :param output_pdb: Path where the generated PDB file should be written. :type output_pdb: str or pathlib.Path :returns: Path to the generated PDB file. :rtype: pathlib.Path .. py:method:: replace_pdb_residue_name(pdb_file, old_resname, new_resname) Replace residue names in a PDB file. :param pdb_file: PDB file to modify. :type pdb_file: str or pathlib.Path :param old_resname: Existing residue name to replace. :type old_resname: str :param new_resname: New residue name to write. :type new_resname: str .. rubric:: Notes OpenBabel commonly writes generated structures using the residue name `UNL`. AmberTools workflows usually need this to be replaced with the assigned trimer residue code. .. py:method:: run_command(command, workdir=None) Run a shell command and report its output. :param command: Command to execute. :type command: str :param workdir: Working directory in which to run the command. :type workdir: str or pathlib.Path, optional :returns: Completed subprocess result. :rtype: subprocess.CompletedProcess :raises RuntimeError: Raised if the command exits with a non-zero return code. .. py:method:: build_PHA_copolymer(PHA_types, length, pattern=None, sequence_mode='pattern', forcefield='gaff2', random_seed=None) Build a PHA copolymer from existing PHA monomer-unit prepins. .. rubric:: Examples Patterned AB copolymer:: build_PHA_copolymer( PHA_types=["3HB", "4HB"], length=10, pattern="AB", sequence_mode="pattern", ) Random copolymer:: build_PHA_copolymer( PHA_types=["3HB", "4HB"], length=10, sequence_mode="random", ) Output names ------------ Patterned:: co_P3HB_P4HB_AB Random:: co_P3HB_P4HB_rand .. py:method:: get_monomer_smiles(PHA_type) Get the monomer SMILES for a PHA type from residue_codes.csv. .. py:method:: generate_polymer_smiles_from_sequence(monomer_smiles_sequence) Generate a polymer SMILES string from monomer SMILES. Rule ---- For every monomer except the final one, remove the trailing character before joining. Example ------- ["OCCCC(=O)O", "OCCCC(=O)O", "OCCCC(=O)O"] becomes: OCCCC(=O)OCCCC(=O)OCCCC(=O)O .. py:method:: save_polymer_smiles(polymer_name, smiles) Save or update a polymer SMILES entry in polymer_smiles.csv.