pestifer.charmmff.charmmffcontent module¶
This module defines classes that facilitate the handling of CHARMM force field content.
- class pestifer.charmmff.charmmffcontent.CHARMMFFContent(*args, **kwargs)[source]¶
Bases:
CacheableObjectHolds all CHARMM force field content parsed for use within Pestifer.
The CHARMM force field is downloadable directly from the MacKerell lab at the University of Maryland: https://mackerell.umaryland.edu/charmm_ff_params.html Pestifer uses its own local copies of release tarballs, one per version directory.
- Parameters:
charmmff_path (str or Path) – Path to the version-specific directory (e.g.
resources/charmmff/jul24/) containing the release tarball,custom/,patches/, andpdbrepository/subdirectories.tarfilename (str, optional) – Override for the tarball name. If omitted, derived from the directory name as
toppar_c36_{version_key}.tgz.
- add_custom_directory(user_custom_directory: str | Path)[source]¶
Add a user custom directory to the
CHARMMFFContent. This directory should contain custom files that can be used in addition to the standard CHARMM force field files.Each
.rtf/.top/.strfile in the directory is scanned forRESI/PREScards so that residues and patches it defines become discoverable viaget_topfile_of_resname(), and anyMASScards are merged intomassdict. This keeps the auto-discovery used by the psfgen task consistent whether the rest of the CHARMM content was rebuilt from the tarball or hydrated from cache.- Parameters:
user_custom_directory (str) – The path to the user custom directory containing additional CHARMM files.
- Raises:
NotADirectoryError – If the specified path is not a directory.
- copy_charmmfile_local(basename: str) str[source]¶
Copy a NAMD-friendly version of a CHARMMFF file to the local directory. This function checks if the file already exists in the current working directory. If it does, it returns the basename. If the file is found in the custom files, it copies it from there. If the file is found in the tarball or any custom directory, it extracts it and writes it to the local directory, filtering out CHARMM commands that give NAMD trouble. If the file is not found in either location, it logs a warning.
- find_resis_and_patches(resnames: list[str] = [])[source]¶
Find all residues in the CHARMM force field content and associate each with its topology file. This function scans all topology files for lines that start with
RESIorPRESand extracts the residue names. It creates a dictionary mapping residue names to the topology files they are found in. The residues are stored in theresiduesattribute and the patches in thepatchesattribute.
- get_pres(presname: str) CharmmResi | None[source]¶
- get_resi(resname: str) CharmmResi | None[source]¶
- get_resnames_of_streamID(streamID: str, substreamID: str = '') list[str][source]¶
Given a streamID and optional substreamID, return a list of all residue names defined in that stream.
- class pestifer.charmmff.charmmffcontent.CHARMMFFResiTopCollection(*args, **kwargs)[source]¶
Bases:
CacheableObjectA collection of CHARMM residue topology data.
- class pestifer.charmmff.charmmffcontent.CHARMMFFStreamID(charmmff_filename: str)[source]¶
Bases:
objectA class for handling the CHARMM force field stream ID and substream ID.
This class parses the filename of a CHARMM force field file to extract the stream ID and substream ID.
- Parameters:
charmmff_filename (str) – The name of the CHARMM force field file.
- pestifer.charmmff.charmmffcontent.charmmff_version_key(version_str: str) str[source]¶
Parse a CHARMMFF version string in the format ‘MonthYEAR’ and return the version key (e.g. ‘jul24’, ‘feb26’).
- pestifer.charmmff.charmmffcontent.extract_mass_lines(file_contents)[source]¶
Extract lines containing mass information from the CHARMM force field files. This function scans the contents of a CHARMM force field file and returns lines that start with
MASS.- Parameters:
file_contents (str) – The contents of the CHARMM force field file to scan for mass information.
- pestifer.charmmff.charmmffcontent.extract_resi_pres_blocks(text: str, keywords: tuple[str, ...] = ('RESI', 'PRES'))[source]¶
Extract blocks of text starting with RESI or PRES and ending before the next RESI, PRES, ATOMS, end, or EOF.
This function uses a regular expression to find blocks of text that start with the specified keywords and continue until the next occurrence of one of the keywords or the end of the file.
- Parameters:
- Returns:
A list of strings, each containing a block of text that starts with one of the specified keywords.
- Return type:
- pestifer.charmmff.charmmffcontent.parse_conditional_script(script_text)[source]¶
Parse a conditional script text and return a dictionary with parsed lines and variables.
This function processes a script that contains conditional statements and variable assignments. It supports ‘set’ commands to define variables and ‘if’ statements to conditionally execute blocks of code.
This function was written by ChatGPT 4o.
- Parameters:
script_text (str) – The script text to parse, which may contain ‘set’, ‘if’, and ‘endif’ statements.
- Returns:
A dictionary with two keys:
parsed: a string containing the processed script text with comments and conditionals resolved.vars: a dictionary of variables defined in the script.
- Return type: