Utils subpackage

This is SWAMP: Solving structures With Alpha Membrane Pairs

This module implements useful classes and methods used across all modules in SWAMP

SwampLibrary(*args, **kwargs)[source]

SwampLibrary instance

TargetSplit(*args, **kwargs)[source]

TargetSplit instance

ThreadResults(*args, **kwargs)[source]

ThreadResults instance

compress(fname, out=None)[source]

Compress a text file into .gz

Parameters:
  • fname (str) – the file name to be compressed
  • out (str) – specify an output file name, otherwise default is fname.gz
Returns:

compressed file name (str)

create_tempfile(content, mode='w')[source]

Create a temporary file with a given set of contents

Parameters:
  • content (str) – content to dump into the temporary file
  • mode (str) – mode to open the file handler (default: ‘w’)
Returns:

the path to the temporary file name (str)

decompress(fname, out=None)[source]

Decompress a .gz file into text file

Parameters:
  • fname (str) – the file name to be decompressed
  • out (str) – specify an output file name, otherwise default is fname without .gz
Returns:

the decompressed file name (str)

extract_fragment_cmap(pdb_hierarchy, helices)[source]

Method to extract the interhelical contact map of a given pdb file

:param Structure pdb_hierarchy: the pdb hierarchy of the fragment :param tuple helices: a nested list with the listed residues numbers of the helices of interest :returns: the contact map with the interhelical contacts (ContactMap)

extract_hierarchy(full_hierarchy, to_extract, chainID=None)[source]

Method to extract a given set of residues from a pdbfile in form of a gemmi structure hierarchy

:param Structure full_hierarchy: pdb hierarchy of interest :param tuple to_extract: list with the residue numbers to be extracted :param str chainID: the chain id where the residues to be extracted are located (default None) :returns: a new Structure hierarchy containing the extracted residues

extract_hierarchy_seqnumber(hierarchy, seq_numbers, chain_id='A')[source]

Extract the hierarchy corresponding with a given set of residue sequence numbers. Considers missing residues.

:argument Structure hierarchy: original hierarchy to trim :argument tuple seq_numbers: residue sequence number to extract :argument str chain_id: chain where the residues should be extracted from :returns: a new Structure with the residues of interest

:example

>>> import gemmi
>>> from swamp.utils import extract_hierarchy_seqnumber
>>> hierarchy = gemmi.read_structure('/mnt/sda1/MR_edge_cases/3txt_MR/3txt.pdb')
>>> subtrgt_1 = extract_hierarchy_seqnumber(hierarchy, [x for x in range(104 ,125)] + [x for x in range(158, 179)])
>>> subtrgt_1.write_minimal_pdb('/home/filo/test.pdb')
extract_interhelical_cmap(cmap, helices, residues, new_id, score_threshold=0.0)[source]

Method to extract the interhelical contacts

:param ContactMap cmap: the contact map of interest :param tuple helices: a nested list with the listed residue numbers of the two helices of interest :param str new_id: the new identifies given to the resulting contact map :param float score_threshold: the raw score threshold at which contacts will be included (default 0.0) :returns: inverted_cmap: the contact map containing only the inter-helical contacts between the pair of helices (ContactMap)

get_missing_residues(header_list)[source]

Get a dictionary with the missing residues described in the REMARK section of a pdb file

Parameters:header_list (tuple) – a list with the lines of the header section of the pdb file
Returns:a dictionary with the missing residues present in each chain (chain ids are used as keys)
get_tempfile()[source]

Method to get a temporary file name

Returns:temporary file name (str)
invert_contactmap(cmap)[source]

Method to invert a contact map

:param ContactMap cmap: the contact map of interest :returns: and inverted_cmap: the contact map corresponding with the inverted sequence (1-res_seq) (ContactMap)

invert_hiearchy(hierarchy)[source]

Method to return the inverted hierarchy (1-res_seq)

:param Structure hierarchy: pdb hierarchy to be inverted :returns: the Structure hierarchy corresponding with the inverted sequence (1-res_seq)

merge_hierarchies(hiearchies, new_chain_id='A', new_model_id='1', renumber=False)[source]

Method to merge two given hierarchies into one (same chain and model)

Parameters:
  • hiearchies (tuple) – a list with the pdb hierarchies to be merged
  • new_chain_id (str) – the new chain id for the result hierarchy
  • new_model_id (str) – the new model name for the result hierarchy
  • renumber (bool) – if True the residues of the resulting hierarchy will be renumbered starting at 1
Returns:

a new Structure hierarchy corresponding to the merged input hierarchies

merge_into_ensemble(hierarchies)[source]

Method to merge a series of hierarchies into an ensemble where each of the original hierarchies is represented as a model

Parameters:hierarchies (tuple) – the hierarchies that will merged to form an ensemble
Returns:a new Structure hierarchy containing the ensemble
remove(path)[source]
renumber_hierarchy(hierarchy, start=1)[source]

Method to renumber a given hierarchy to start in a given value. Renumbered inplace

:param Structure hierarchy: pdb hierarchy to be renumbered :param int start: first residue to start renumbering of the hierarchy

split_ensemble_into_models(hierarchy)[source]

Method to split a ensemble into its constituent models

:argument Structure hierarchy: the input ensemble to be splited :returns: a tuple containing Structure, each formed by a single model originating from the input ensemble

touch(fname, content='', mode='w')[source]

Create a file with the specified contents

Parameters:
  • fname (str) – file name to be created
  • content (str) – content to write into the file (default ‘’)
  • mode (str) – mode to open the file handler (default: ‘w’)