API documentation¶
-
class
psfgen.
PsfGen
(output=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, case_sensitive=False)¶ A Psf generator object. Represents the state of a single molecular system, with its own set of loaded topologies, residue and/or atom aliases, segments, and coordinates.
-
add_segment
(segid, first='none', last='none', pdbfile=None, auto_angles=True, auto_dihedrals=True, residues=None, mutate=None)¶ Adds a new segment to the internal molecule state.
Parameters: - segid (str) – Name/ID of the new segment
- first (str) – Patch to apply to first residue in segment, or None for topology file default setting
- last (str) – Patch to apply to last residue in segment, or None for topology file in default setting
- pdbfile (str) – PDB file to read residue information from, or None to create an empty segment
- auto_angles (bool) – If angles should be autogenerated.
- auto_dihedrals (bool) – If dihedrals should be autogenerated.
- residues (list of 2 or 3-tuple) – (resid, residue, [chain]) of residues to append to the end of the segment. Chain can be None or unset in this tuple to use the current chain.
- mutate (list of 2 tuple) – (resid, resname) of residues to alter. The given residue IDs will be set to the given residue name.
-
alias_atom
(resname, top_atomname, pdb_atomname)¶ Set a correspondence between an atom name in a specific residue in a PDB file and in the defined topologies.
Parameters: - resname (str) – Residue name in which to make alias
- top_atomname (str) – Atom name in the topology file
- pdb_atomname (str) – Equivalent atom name in PDB file
-
alias_residue
(top_resname, pdb_resname)¶ Set a correspondence between a residue name in a PDB file and in the defined topologies. The topology residue names should be treated as the canonical set here.
Parameters: - top_resname (str) – Resname in topology file
- pdb_resname (str) – Equivalent resname in PDB files
-
case_sensitive
¶ Determines whether or not residue and other names have case sensitivity. Defaults to False. Can only be changed before reading in any topology files.
-
delete_atoms
(segid, resid=None, atomname=None)¶ Deletes atoms from the molecule, with options for increasing specificity. As many atoms as match the passed options will be deleted, so for example if only segid is present, an entire segment will be removed.
Parameters: - segid (str) – Segment ID of atom(s) to delete
- resid (str or int) – Residue ID of atom(s) to delete, or None to delete entire matching segment
- atomname (str) – Atom name to delete, or None to delete entire matching segment or residue
-
get_atom_indices
(segid, resid)¶ Obtains atom indices/IDs in a given residue
Parameters: - segid (str) – Segment ID to query
- resid (str or int) – Residue ID to query
Returns: (list of int) – Atom IDs in residue
-
get_atom_names
(segid, resid)¶ Obtains atom names in a given residue
Parameters: - segid (str) – Segment ID to query
- resid (str or int) – Residue ID to query
Returns: (list of str) – Atom names in residue
-
get_charges
(segid, resid)¶ Obtains atom charges in a given residue
Parameters: - segid (str) – Segment ID to query
- resid (str or int) – Residue ID to query
Returns: (list of float) – Atom charges in residue
-
get_coordinates
(segid, resid)¶ Obtains atom coordinates in a given residue
Parameters: - segid (str) – Segment ID to query
- resid (str or int) – Residue ID to query
Returns: (list of 3-tuple) – (x,y,z) position of all atoms in residue
-
get_first
(segid)¶ Get the name of the patch applied to the beginning of a given segment
Parameters: segid (str) – Segment ID to query Returns: (str) – Patch name, or None
-
get_last
(segid)¶ Get the name of the patch applied to the end of a given segment
Parameters: segid (str) – Segment ID to query Returns: (str) – Patch name, or None
-
get_masses
(segid, resid)¶ Obtains atom masses in a given residue
Parameters: - segid (str) – Segment ID to query
- resid (str or int) – Residue ID to query
Returns: (list of float) – Atom masses in residue
-
get_patches
(list_defaults=True, list_all=False)¶ Obtain information about available or applied patches in the current system state.
Parameters: - list_defaults (bool) – If True, default patches will be listed too. Otherwise only explicitly applied patches will be shown. Defaults to True
- list_all (bool) – List all available patches, not just applied ones. For psfgen internal reasons, “NONE”, “None”, and “none” will appear in this list.
Returns: (list of 3-tuple) – (patchname, segid, resid) of all applied patches
-
get_resids
(segid)¶ Obtain all currently defined resids in a given segment
Parameters: segid (str) – Segment ID to query Returns: (list of str) – All defined resids in given segment
-
get_residue_types
()¶ Get all defined residues
Returns: (list of str) – Defined residue types from current topologies
-
get_resname
(segid, resid)¶ Obtains the residue name given a resid and segment
Parameters: - segid (str) – Segment ID to query
- resid (str or int) – Residue ID to query
Returns: (str) – Residue name
-
get_segids
()¶ Obtain all the currently defined segment IDs.
Returns: (list of str) – All defined segids in current molecule
-
get_topologies
()¶ Get all loaded topology files
Returns: (list of str) – Filenames that have been loaded
-
get_velocities
(segid, resid)¶ Obtains atom velocities in a given residue, if set
Parameters: - segid (str) – Segment ID to query
- resid (str or int) – Residue ID to query
Returns: (list of 3-tuple) – (vx,vy,vz) velocities of all atoms in residue
-
guess_coords
()¶ Sets unset coordinates using geometric assumptions
-
patch
(patchname, targets)¶ Applies a patch to the molecule.
Parameters: - patchname (str) – Name of the patch to apply
- targets (list of 2 tuple) – (segid, resid) to apply patch to
-
query_segment
(task, segid=None, resid=None)¶ Ask for information about a segment.
Parameters: - task (str) – In [first, last, residue, resids, segids] depending on what information is desired.
- segid (str) – Segment ID to query
- resid (str) – Residue ID to query, if task is “residue”
Returns: (str or list of str) – Requested information
-
read_coords
(filename, segid)¶ Reads in coordinates from a PDB file, matching segment, residue, and atom names to the current segment.
Parameters: - filename (str) – Filename of PDB file to read
- segid (str) – Segment ID to assign coordinates to
-
read_psf
(filename, pdbfile=None, namdbinfile=None, velnamdbinfile=None)¶ Reads structure information from a PSF file and adds it to the internal molecule state. Can also read insertion codes and coordinates from a PDB file, and/or coordinates from a NAMD binary file, if atoms are in the same order. Can read velocities from a NAMD binary file as well.
The PSF file is read in and also kind of interpreted: topology files in the REMARKS section are loaded, and a new segment is created with the segid specified in the PSF file. Note that if the topology files cannot be found, they will still be listed as “loaded” in the internal PsfGen state.
Parameters: - filename (str) – PSF file to read
- pdbfile (str) – PDB file to obtain coordinates, elements, and insertion codes from. Atoms must be in same order as the PSF.
- namdbinfile (str) – Binary NAMD file to read coordinates from. Will take priority over coordinates in pdbfile, if specified. Atoms must be in the same order as the PSF.
- velnamdbinfile (str) – Binary NAMD file to read velocities from. Atoms must be in the same order as the PSF.
-
read_topology
(filename)¶ Parses a charmm format topology file into current library.
Parameters: filename (str) – File to parse
Raises: FileNotFoundError
– If the file cannot be opened for readingValueError
– If an error occurs during parsing
-
regenerate_angles
()¶ Removes angles and regenerates them from bonds. Can be used after patching.
-
regenerate_dihedrals
()¶ Removes dihedrals and regenerates them from angles. Can be used after patching. Usually, you should call regenerate_angles first.
-
regenerate_resids
()¶ Regenerates residue IDs by removing insertion codes and minimially modifying them for uniqueness.
-
set_atom_name
(segid, resid, atomname, new_atomname)¶ Renames an atom
Parameters: - segid (str) – Segment ID of atom to update
- resid (str or int) – Residue ID of atom to update
- atomname (str) – Name of atom to update
- new_atomname (str) – New atom name
-
set_beta
(segid, resid, atomname, beta)¶ Updates the beta-factor of an atom
Parameters: - segid (str) – Segment ID of atom to update
- resid (str or int) – Residue ID of atom to update
- atomname (str) – Name of atom to update
- beta (float) – New beta factor
-
set_charge
(segid, resid, atomname, charge)¶ Updates the charge of an atom
Parameters: - segid (str) – Segment ID of atom to update
- resid (str or int) – Residue ID of atom to update
- atomname (str) – Name of atom to update
- charge (float) – New charge
-
set_mass
(segid, resid, atomname, mass)¶ Updates the mass of an atom
Parameters: - segid (str) – Segment ID of atom to update
- resid (str or int) – Residue ID of atom to update
- atomname (str) – Name of atom to update
- mass (float) – New mass
-
set_position
(segid, resid, atomname, position)¶ Sets the coordinates of a given atom to new values.
Parameters: - segid (str) – Segment ID of atom
- resid (str or int) – Residue ID of atom
- atomname (str) – Atom name
- position (3-tuple or 3-list of double) – New x, y, and z coordinates for atom
-
set_resname
(segid, resid, new_resname)¶ Renames a residue
Parameters: - segid (str) – Segment ID of residue to update
- resid (str or int) – Residue ID to update
- new_resname (str) – New residue name
-
set_segid
(segid, new_segid)¶ Renames a segment.
Parameters: - segid (str) – Segment ID to change
- new_segid (str) – New segment ID
-
set_velocity
(segid, resid, atomname, velocity)¶ Sets the velocity of a given atom to new values
Parameters: - segid (str) – Segment ID of atom
- resid (str or int) – Residue ID of atom
- atomname (str) – Atom name
- velocity (3 membered list or tuple of double) – New vx, vy, vz velocities for atom
-
write_namdbin
(filename, velocity_filename=None)¶ Writes the current molecule state as a NAMD binary file. This file format can only contain coordinate information for each atom. Optionally write velocities to another NAMD binary file.
Parameters: - filename (str) – Filename to write to
- velocity_filename (str) – If present, filename to write velocities to
-
write_pdb
(filename)¶ Writes the current molecule state out as a pdb file
Parameters: filename (str) – Filename to write to
-
write_psf
(filename, type='x-plor')¶ Writes the current molecule state out as a psf file
Parameters: - filename (str) – Filename to write to
- type (str) – Type of psf file to write, in [“charmm”, “x-plor”]
-