pestifer.psfutil.psfcontents module

Definition of the PSFContents class for parsing and managing PSF topology files. This class reads a PSF file, extracts topology information such as atoms, bonds, angles, dihedrals, and patches, and provides methods for accessing and manipulating this data.

class pestifer.psfutil.psfcontents.PSFContents(filename: str, topology_segtypes: list[str] = [], parse_topology: list[str] = [])[source]

Bases: object

A class for parsing and managing PSF topology files. This class reads a PSF file, extracts topology information such as atoms, bonds, angles, dihedrals, and patches, and provides methods for accessing and manipulating this data.

atoms

A list of atoms parsed from the PSF file, represented as instances of the PSFAtom class.

Type:

PSFAtomList

atomserials

A list of serial numbers corresponding to the atoms in the PSF file.

Type:

list

ssbonds

A list of disulfide bonds parsed from the PSF file, represented as instances of the SSBond class. These appear in psfgen-generated PSF files as patches of type ‘DISU’.

Type:

SSBondList

A list of links parsed from the PSF file, represented as instances of the Link class. These appear in psfgen-generated PSF files as patches recognized as creating covalent bonds between atoms in two different residues OTHER than disulfides.

Type:

LinkList

patches

A dictionary containing patches defined in the PSF file, where keys are patch types (e.g., ‘NTER’, ‘CTER’) and values are lists of patch definitions.

Type:

dict

bonds

A list of bonds parsed from the PSF file, represented as instances of the PSFBond class. This attribute is only set if the parse_topology parameter includes bonds.

Type:

PSFBondList, optional

angles

A list of angles parsed from the PSF file, represented as instances of the PSFAngle class. This attribute is only set if the parse_topology parameter includes angles.

Type:

PSFAngleList, optional

dihedrals

A list of dihedrals parsed from the PSF file, represented as instances of the PSFDihedral class. This attribute is only set if the parse_topology parameter includes dihedrals.

Type:

PSFDihedralList, optional

pairex

A list of cross-topology non-bonded pair exclusions parsed from the PSF file, represented as instances of the PSFPairEx class. Used in the dual-topology alchemical free energy paradigm to suppress interactions between atoms belonging to opposite end-states. This attribute is only set if the parse_topology parameter includes pairex.

Type:

PSFPairExList, optional

Parameters:
  • filename (str) – The path to the PSF file to be read.

  • topology_segtypes (list, optional) – A list of segment types to include in the topology parsing. If provided, only atoms of these segment types will be included in the topology. Default is an empty list, which means all atoms will be included.

  • parse_topology (list, optional) – A list of topology elements to parse from the PSF file. Possible values are ‘bonds’, ‘angles’, ‘dihedrals’, ‘impropers’, and ‘pairex’. If provided, the class will parse the specified topology elements from the PSF file. Default is an empty list, which means no topology elements will be parsed.

add_ligands()[source]

Add ligands to each atom based on the bonds defined in the PSF file. This method iterates through the atoms and bonds, establishing ligand relationships by adding each bonded atom to the ligand list of the corresponding atom. It ensures that each atom’s ligands are correctly populated based on the bonds defined in the PSF file.

Raises:

AssertionError – If the bonds attribute is not set or if the atom serial numbers do not match the expected indices.

apply_atom_logics(inclusion_logics: list[str] = [], exclusion_logics: list[str] = [])[source]

Apply inclusion and exclusion logic to the atoms in the PSF contents.

Parameters:
  • inclusion_logics (list[str], optional) – A list of inclusion logic strings to apply to the atoms.

  • exclusion_logics (list[str], optional) – A list of exclusion logic strings to apply to the atoms.

get_charge()[source]

Calculate the total charge of the system by summing the charges of all atoms.

Returns:

The total charge of the system, calculated as the sum of the charges of all atoms in the PSF file.

Return type:

float

remove_ignored_residues(ignored_residues: ResidueList)[source]

Remove ignored residues from the PSF contents.

Parameters:

ignored_residues (ResidueList) – A list of residues to remove from the PSF contents.

write(filename: str)[source]

Write the PSF contents to a file in EXT PSF format.

The ATOM section is rebuilt from the current atoms list; all other sections are written verbatim from the lines read at parse time.

Parameters:

filename (str) – Path of the output PSF file.

class pestifer.psfutil.psfcontents.PSFResidue(resname: str = '', resid: pestifer.objs.resid.ResID = <factory>, segname: str = '', atoms: pestifer.psfutil.psfatom.PSFAtomList = <factory>, segtype: str = '')[source]

Bases: object

add_atom(atom: PSFAtom)[source]
atoms: PSFAtomList
resid: ResID
resname: str = ''
segname: str = ''
segtype: str = ''
class pestifer.psfutil.psfcontents.PSFResidueList(initlist=None)[source]

Bases: UserList[PSFResidue]

apply_segtypes()[source]

Apply segment types to residues based on their residue names. This method uses the segtype_of_resname mapping to assign segment types to residues based on their residue names. It updates the segtype attribute of each residue in the residue list.

class pestifer.psfutil.psfcontents.PSFSegment(segname: str = '', residues: pestifer.psfutil.psfcontents.PSFResidueList = <factory>, commands: list[str] = <factory>, segtype: str = '')[source]

Bases: object

add_residue(residue: Residue)[source]
commands: list[str]
remarkify(remark: PSFSegmentRemark)[source]
residues: PSFResidueList
segname: str = ''
segtype: str = ''
validate()[source]
class pestifer.psfutil.psfcontents.PSFSegmentList(initlist=None)[source]

Bases: UserList[PSFSegment]

num_atoms()[source]
num_residues()[source]
remarkify(remarks: PSFSegmentRemarkList)[source]
validate()[source]
pestifer.psfutil.psfcontents.get_toppar_from_psf(filename: str)[source]

Extracts the topology file names from a PSF file. This function reads the PSF file and looks for lines that contain topology information, specifically those that start with ‘ REMARKS topology’. It collects the unique topology file names and returns them as a list. Such lines are written by the psfgen program, so this function expects to operate on a PSF file generated by psfgen.