import nanome
from nanome._internal.structure.models import _Molecule
from nanome._internal.network import PluginNetwork
from nanome._internal.enums import Messages
from nanome.util import Logs
from . import Base
from ._deprecated import MoleculeDeprecated
[docs]class Molecule(_Molecule, MoleculeDeprecated, Base):
"""
| Represents a molecule. Contains chains.
"""
[docs] def add_chain(self, chain):
"""
| Add a chain to this molecule
:param chain: Chain to add to the molecule
:type chain: :class:`~nanome.structure.Chain`
"""
chain.index = -1
self._add_chain(chain)
[docs] def remove_chain(self, chain):
"""
| Remove a chain from this molecule
:param chain: Chain to remove from the molecule
:type chain: :class:`~nanome.structure.Chain`
"""
chain.index = -1
self._remove_chain(chain)
# region Generators:
@property
def chains(self):
"""
| The chains of this complex
:type: :class:`generator` <:class:`~nanome.structure.Chain`>
"""
for chain in self._chains:
yield chain
@chains.setter
def chains(self, chain_list):
self._chains = chain_list
@property
def residues(self):
"""
| The residues of this complex
:type: :class:`generator` <:class:`~nanome.structure.Residue`>
"""
for chain in self.chains:
for residue in chain.residues:
yield residue
@property
def atoms(self):
"""
| The atoms of this complex
:type: :class:`generator` <:class:`~nanome.structure.Atom`>
"""
for residue in self.residues:
for atom in residue.atoms:
yield atom
@property
def bonds(self):
"""
| The bonds of this complex
:type: :class:`generator` <:class:`~nanome.structure.Bond`>
"""
for residue in self.residues:
for bond in residue.bonds:
yield bond
# endregion
# region connections
@property
def complex(self):
"""
| Complex that the molecule belongs to
"""
return self._complex
# endregion
# region all fields
@property
def name(self):
"""
| Represents the name of the molecule
:type: :class:`str`
"""
return self._name
@name.setter
def name(self, value):
if type(value) is not str:
value = str(value)
self._name = value
@property
def associated(self):
"""
| Metadata associated with the molecule.
| PDB REMARKs end up here.
:type: :class:`dict`
"""
return self._associated
@associated.setter
def associated(self, value):
self._associated = value
# endregion
# region conformer stuff
@property
def names(self):
return self._names
@names.setter
def names(self, value):
if len(value) != self._conformer_count:
raise ValueError("Length of associateds must match the conformer count of the molecule.")
self._names = value
@property
def associateds(self):
return self._associateds
@associateds.setter
def associateds(self, value):
if len(value) != self._conformer_count:
raise ValueError("Length of associateds must match the conformer count of the molecule.")
self._associateds = value
@property
def conformer_count(self):
return self._conformer_count
@property
def current_conformer(self):
return self._current_conformer
@current_conformer.setter
def current_conformer(self, value):
""""value: int"""
self._current_conformer = value
# endregion
[docs] def get_substructures(self, callback=None):
expects_response = callback is not None or nanome.PluginInstance._instance.is_async
id = PluginNetwork.send(Messages.substructure_request, (self.index, nanome.util.enums.SubstructureType.Unkown), expects_response)
return nanome.PluginInstance._save_callback(id, callback)
[docs] def get_ligands(self, callback=None):
expects_response = callback is not None or nanome.PluginInstance._instance.is_async
id = PluginNetwork.send(Messages.substructure_request, (self.index, nanome.util.enums.SubstructureType.Ligand), expects_response)
return nanome.PluginInstance._save_callback(id, callback)
[docs] def get_proteins(self, callback=None):
expects_response = callback is not None or nanome.PluginInstance._instance.is_async
id = PluginNetwork.send(Messages.substructure_request, (self.index, nanome.util.enums.SubstructureType.Protein), expects_response)
return nanome.PluginInstance._save_callback(id, callback)
[docs] def get_solvents(self, callback=None):
expects_response = callback is not None or nanome.PluginInstance._instance.is_async
id = PluginNetwork.send(Messages.substructure_request, (self.index, nanome.util.enums.SubstructureType.Solvent), expects_response)
return nanome.PluginInstance._save_callback(id, callback)
_Molecule._create = Molecule