Lib higher level

Higher level functions.

Function which operate with several libraries and are defined here to avoid circular imports.

idpconfgen.libs.libhigherlevel.bgeo_reduce(bgeo)[source]

Reduce BGEO DB to trimer and residue scopes.

idpconfgen.libs.libhigherlevel.cli_helper_calc_bgeo(fname, fdata, **kwargs)[source]

Help cli_bgeodb to operate.

Returns:

dict – key: fname value -> dict, Ca_C_Np1, Ca_C_O, Cm1_N_Ca, N_Ca_C

idpconfgen.libs.libhigherlevel.cli_helper_calc_torsions(fname, fdata, **kwargs)[source]

Help cli_torsion to operate.

Returns:

dict – key: fname value: -> dict, phi, phi, omega -> list of floats

idpconfgen.libs.libhigherlevel.cli_helper_calc_torsionsJ(fdata_tuple, **kwargs)[source]

Help cli_torsionsJ.py.

idpconfgen.libs.libhigherlevel.convert_bond_geo_lib(bond_geo_db)[source]

Convert bond geometry library to bond type first hierarchy.

Restructure the output of read_trimer_torsion_planar_angles such that the main keys are the bond types, followed by the main residue, the pairs in the trimer, and, finally, the torsion angles.

Parameters:

bond_geo_db (dict) – The output of read_PDBID_from_source.

Returns:

dict

idpconfgen.libs.libhigherlevel.download_pipeline(func, logfilename='.download')[source]

Context pipeline to download PDB/mmCIF files.

Exists because fetching and download filtered PDBs shared the same operational contextm, only differing on the function which orchestrates the download process.

Parameters:
  • func (function) – The actual function that orchestrates the download operation.

  • logfilename (str, optional) – The common stem name of the log files.

idpconfgen.libs.libhigherlevel.extract_secondary_structure(pdbid, ssdata, atoms='all', minimum=0, structure='all')[source]

Extract secondary structure elements from PDB data.

Parameters:
  • pdbid (tuple) – Where index 0 is the PDB id code, for example 12AS.pdb, or 12AS_A, or 12AS_A_seg1.pdb. And, index 1 is the PDB data itself in bytes.

  • ssdata (dict) – Dictionary containing the DSSP information. Must contain a key equal to Path(pdbid).stem, where `dssp key contains the DSSP information for that PDB.

  • atoms (str or list of str or bytes, optional) – The atom names to keep. Defaults to all.

  • minimum (int, optional) – The minimum size a segment must have in order to be considered. Defaults to 0.

  • structure (str or list of chars) – The secondary structure character to separate. Multiple can be given in the form of a list.

idpconfgen.libs.libhigherlevel.get_bond_geos(fdata)[source]

Calculate bond angles from structure.

Parameters:
idpconfgen.libs.libhigherlevel.get_separate_torsions(torsions_array)[source]

Separate torsion angles according to the protein backbone concept.

Considers torsion angles for bonds in between atom pairs:
  • CA - C

  • C - N

  • N - CA

Backbone obeys the order: N-CA-C-N-CA-C(…)

And the first value corresponds to a CA-C pair, because the first N-CA pair of the protein backbone has no torsion angle.

idpconfgen.libs.libhigherlevel.get_torsions(fdata, degrees=False, decimals=3, validate=True)[source]

Calculate torsion angles from structure.

Corrects for labels not sorted according to (N, CA, C). But does not correct for non-sorted residues (do these exist?).

Calculates torsion angles with :func:libcalc.calc_torsion_angles.

Parameters:
  • fdata (str, bytes or Path) – A path to the structure file, or the string representing the file. In fact, accepts any type :class:libstructure.Structure would accept.

  • degrees (bool, optional) – Whether to return torsion angles in degrees or radians.

  • decimals (int, optional) – The number of decimals to return. Defaults to 3.

  • validate (bool) – Validates coordinates and labels according to general expectations. Expectations are as described by functions: - :func:libhigherlevel.validate_backbone_labels_for_torsion - :func:libhigherlevel.validate_coords_for_backbone_torsions

    If False, does not perform validation. Be sure to provide PDBs what will output meaningful results.

Returns:

np.ndarray – As described in :func:libcalc.calc_torsion_angles() but with decimals and degrees applied.

See also

libhigherlevel.validate_backbone_labels_for_torsion, libhigherlevel.validate_coords_for_backbone_torsions, libcalc.calc_torsion_angles

idpconfgen.libs.libhigherlevel.get_torsionsJ(fdata, decimals=5, degrees=False, hn_terminal=True, hn_labels=('H', 'H1'), proline_value=nan)[source]

Calculate HN-CaHA torsion angles from a PDB/mmCIF file path.

Needs atom labels: H or H1, N, CA, HA or HA2 (Glycine).

Parameters:
  • decimals (int) – The decimal number to round the result.

  • degrees (bool) – Whether or not to return values as degrees. If False returns radians.

  • hn_terminal (bool) – If the N-terminal has no hydrogens, flag hn_terminal should be

  • provided as `False`, and the first residue will be discarded.

  • If `True` expects N-terminal to have `H` or `H1`.

Returns:

np.ndarray – The NH-CaHA torsion angles for the whole protein. Array has the same length of the protein if N-terminal has H, otherwise has length of protein minus 1.

Notes

Not optimized for speed. Not slow either.

idpconfgen.libs.libhigherlevel.read_trimer_torsion_planar_angles(pdb, bond_geometry)[source]

Create a trimer/torsion library of bend/planar angles.

Given a PDB file:

  1. reads each of its trimers, and for the middle residue:

  2. Calculates phi/psi and rounds them to the closest 10 degree bin

  3. assign planar angles found for that residue to the trimer/torsion key.

  4. the planar angles are converted to the format needed by cli_build, which is that of (pi - angle) / 2.

  5. updates that information in bond_gemetry.

Created key:values have the following form in bond_geometry dict:

{
    'AAA:10,-30': {
        'Cm1_N_Ca': [],
        'N_Ca_C': [],
        'Ca_C_Np1': [],
        'Ca_C_O': [],
        }
    }
Parameters:
  • pdb (any input of libstructure.Structure) – The PDB/mmCIF file data.

  • bond_geometry (dict) – The library dictionary to update.

Returns:

None

idpconfgen.libs.libhigherlevel.validate_backbone_labels_for_torsion(labels, minimum=2)[source]

Validate labels for torsion angle calculation.

Assumes labels are aligned with their corresponding coordinates. Yet, coordinates have no scope in this function.

Excepts only the mininal backbone labels, these are: N, CA, and C.

Parameters:
  • labels (np.array of shape (N,) or alike) – Where N % 3 equals 0.

  • minimum (int) – The minimum number of residues to consider valid.

idpconfgen.libs.libhigherlevel.validate_coords_for_backbone_torsions(coords, minimum=2)[source]

Validate coords for torsions.

Does NOT validate with values have physical sense. Validates only valid input for :func:libcalc.calc_torsion_angles.

Validations performed:

  • coords are two-dimensional arrays

  • coords have 3 values in the first dimension (XYZ) (shape[1])

  • number of coords is multiple of 3.

Returns:

str – A string explaining the error if an error is found. An empty string if no error is found.