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: CacheableObject

Holds 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/, and pdbrepository/ subdirectories.

  • tarfilename (str, optional) – Override for the tarball name. If omitted, derived from the directory name as toppar_c36_{version_key}.tgz.

charmmff_path

Path to the directory containing the CHARMM force field files.

Type:

str

tarfilename

Name of the tarball file containing the CHARMM force field files.

Type:

str

filenamemap

Maps file basenames to their full paths in the CHARMM force field content.

Type:

dict

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/.str file in the directory is scanned for RESI/PRES cards so that residues and patches it defines become discoverable via get_topfile_of_resname(), and any MASS cards are merged into massdict. 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.

static charmmff_filetype(filename: str) str | None[source]
checkout_pdb(name: str) PDBInput | None[source]
clean_local_charmmff_files()[source]

Remove all local CHARMM force field files.

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.

Parameters:

basename (str) – The basename of the CHARMM file to copy. This should be a recognizable CHARMMFF rtf, prm, or str file name without any directory path.

Returns:

The basename of the copied file in the local directory.

Return type:

str

deprovision()[source]
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 RESI or PRES and extracts the residue names. It creates a dictionary mapping residue names to the topology files they are found in. The residues are stored in the residues attribute and the patches in the patches attribute.

get_filename(shortname)[source]
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.

get_topfile_of_resname(resname: str) str | None[source]

Given a residue name, return the name of the CHARMMFF topo or stream file that defines it

provision(force_rebuild: bool = False, resnames: list[str] = [])[source]
provision_pdbrepository(force_rebuild: bool = False, resnames: list[str] = [])[source]
provision_residueobjects(force_rebuild: bool = False, resnames: list[str] = [])[source]
class pestifer.charmmff.charmmffcontent.CHARMMFFResiTopCollection(*args, **kwargs)[source]

Bases: CacheableObject

A collection of CHARMM residue topology data.

class pestifer.charmmff.charmmffcontent.CHARMMFFStreamID(charmmff_filename: str)[source]

Bases: object

A 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.

charmmff_filename

The name of the CHARMM force field file.

Type:

str

streamID

The stream ID extracted from the filename.

Type:

str

substreamID

The substream ID extracted from the filename, if applicable.

Type:

str

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:
  • text (str) – The input text from which to extract the blocks.

  • keywords (tuple of str, optional) – The keywords that indicate the start of a block. Defaults to (RESI, PRES).

Returns:

A list of strings, each containing a block of text that starts with one of the specified keywords.

Return type:

list of str

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:

dict