luna.MyBio.util module¶
- biopython_entity_to_mol(entity, select=<Select all>, validate_mol=True, standardize_mol=True, template=None, add_h=False, ph=None, break_metal_bonds=False, mol_obj_type='rdkit', wrapped=True, openbabel='obabel', tmp_path=None, keep_tmp_files=False)[source]¶
Convert an object
Entity
to a molecular object (MolWrapper
,rdkit.Chem.rdchem.Mol
, oropenbabel.pybel.Molecule
).- Parameters
entity (
Entity
) – The entity to be converted.select (
Select
) – Decide which atoms will be consired. By default, all atoms are accepted.validate_mol (bool) – If True, validate the converted molecule with
MolValidator
.standardize_mol (bool) – If True, standardize the converted molecule. Currently, only residues are standardized as it uses
luna.mol.standardiser.ResiduesStandardiser
by default.template (
luna.mol.template.Template
, optional) – Fix the converted molecule’s bond order based on the bond orders in a template molecule. Thetemplate
should implement assign_bond_order().add_h (bool) – If True, add hydrogen to the converted molecule.
ph (float, optional) – Add hydrogens considering pH
ph
.break_metal_bonds (bool) – If True, remove covalent bonds between residues and metals and fix the residue bond order.
mol_obj_type ({“rdkit”, “openbabel”}) – If “rdkit”, parse the converted molecule with RDKit and return an instance of
rdkit.Chem.rdchem.Mol
. If “openbabel”, parse the converted molecule with Open Babel and return an instance ofopenbabel.pybel.Molecule
. Ifwrapped
is True, the molecular object will be wrapped withMolWrapper
.wrapped (bool) – If True, wrap the molecular object with
MolWrapper
.openbabel (str) – Pathname to Open Babel. Even if
mol_obj_type
is set to ‘rdkit’, this function uses Open Babel to properly parse PDB files and to add hydrogens to the molecule considering different pHs.tmp_path (str) – A temporary directory to where temporary files will be saved. If not provided, the system’s default temporary directory will be used instead.
keep_tmp_files (bool) – If True, keep all temporary files. Otherwise, removes them in the end.
- Returns
mol_obj (
MolWrapper
,rdkit.Chem.rdchem.Mol
, oropenbabel.pybel.Molecule
) – The converted molecule.ignored_atoms (list) – List of ignored atoms. Currently, ignored atoms may contain only metals.
- download_pdb(pdb_id, output_path='.', overwrite=False)[source]¶
Download a PDB file from RCSB.org.
- Parameters
pdb_id (str) – 4-symbols structure Id from PDB (e.g. 3J92).
output_path (str) – Put the PDB file in this directory.
overwrite (bool) – If True, overwrite any existing PDB files.
- entity_to_string(entity, select=<Select all>, write_conects=True, write_end=True, preserve_atom_numbering=True)[source]¶
Convert a Structure object (or a subset of a
Structure
object) to string.This function works on a structural level. That means if
entity
is not aStructure
object, the structure will be recovered directly fromentity
. Therefore, useselect
to select specific chains, residues, and atoms from the structure object.- Parameters
entity (
Entity
) – The PDB object to be converted.select (
Select
) – Decides which atoms will be saved at the output. By default, all atoms are accepted.write_conects (bool) – If True, writes CONECT records.
write_end (bool) – If True, writes the END record.
preserve_atom_numbering (bool) – If True, preserve the atom numbering. Otherwise, re-enumerate the atom serial numbers.
- Returns
The converted
entity
.- Return type
- get_entity_from_entry(entity, entry, model=0)[source]¶
Get a
Chain
orResidue
instance based on the provided entryentry
.- Parameters
entity (
Entity
) – The PDB object to recover the target entry from.entry (
Entry
) – The target entry.model (int) – The PDB model where the entry could be found. The default value is 0.
- Returns
The target entry.
- Return type
Entity
- Raises
MoleculeNotFoundError – If the entry’s molecule was not found in
entity
.ChainNotFoundError – If the entry’s chain was not found in
entity
.
- get_residue_cov_bonds(residue, select=<Select all>)[source]¶
Get covalently bound atoms from residues or other molecules.
- Parameters
residue (
Residue
) – The residue or other molecule from which covalently bound atoms will be recovered.select (
Select
) – Decides which atoms will be consired. By default, all atoms are accepted.
- Returns
List of pairs of covalently bound atoms.
- Return type
list of tuple(
Atom
,Atom
)
- get_residue_neighbors(residue, select=<Select all>)[source]¶
Get all neighbors from a residue.
In the case of an amino acid that is part of a peptide bond, its neighbors are any predecessor or successor residues. The same idea applies to nucleic acids.
- Parameters
residue (
Residue
) – The residue or other molecule from which covalently bound molecules will be recovered.select (
Select
) – Decides which atoms will be consired. By default, all atoms are accepted.
- Returns
neighbors – A dictionary containing the predecessor (
previous
) or successor (next
) molecules.- Return type
dict of {str :
Residue
}
- parse_from_file(pdb_id, file)[source]¶
Read a PDB file and return a
Structure
object.- Parameters
pdb_id (str) – The structure identifier.
file (str) – Pathname of the PDB file.
- Returns
structure – The parsed PDB file as a
Structure
object.- Return type
Structure
- Raises
PDBNotReadError – If the PDB file could not be parsed.
- save_to_file(entity, output_file, select=<Select all>, write_conects=True, write_end=True, preserve_atom_numbering=True)[source]¶
Write a Structure object (or a subset of a
Structure
object) into a file.- Parameters
entity (
Entity
) – The PDB object to be saved.output_file (str) – Save the selected atoms to this file.
select (
Select
) – Decide which atoms will be saved at the PDB output. By default, all atoms are accepted.write_conects (bool) – If True, write CONECT records.
write_end (bool) – If True, write the END record.
preserve_atom_numbering (bool) – If True, preserve the atom numbering. Otherwise, re-enumerate the atom serial numbers.