The Contact Interface of Lahuta
¶
Lahuta
provides two different API's to access built-in contact types:
- functional and
- object-oriented.
The functional API is more concise and easier to use, but the object-oriented API is more flexible and allows for more customization.
In [2]:
Copied!
from lahuta import Luni
from lahuta import Luni
In [3]:
Copied!
luni = Luni('data/2rh1.pdb')
ns = luni.compute_neighbors(radius=4.0, res_dif=4)
luni = Luni('data/2rh1.pdb')
ns = luni.compute_neighbors(radius=4.0, res_dif=4)
Functional API
¶
Previous notebooks already provide plenty of examples of how to use the functional API to the contact interface
In [4]:
Copied!
from lahuta.contacts import F
from lahuta.contacts import F
In [5]:
Copied!
F.polar_hbond_neighbors(ns)
F.polar_hbond_neighbors(ns)
Out[5]:
<Lahuta NeighborPairs class containing 359 atoms and 269 pairs>
Object-Oriented API
¶
Atom-Atom Contacts¶
In [6]:
Copied!
from lahuta.contacts import (
AromaticContacts,
IonicContacts,
HydrophobicContacts,
HBondContacts
)
from lahuta.contacts import (
AromaticContacts,
IonicContacts,
HydrophobicContacts,
HBondContacts
)
In [7]:
Copied!
# aromatic contacts
ac = AromaticContacts(ns)
print (ac.distance)
ac.compute()
ac.results
# aromatic contacts
ac = AromaticContacts(ns)
print (ac.distance)
ac.compute()
ac.results
4.0
Out[7]:
<Lahuta NeighborPairs class containing 66 atoms and 64 pairs>
In [8]:
Copied!
# hydrophobic contacts
hc = HydrophobicContacts(ns)
hc.compute()
hc.results
# hydrophobic contacts
hc = HydrophobicContacts(ns)
hc.compute()
hc.results
Out[8]:
<Lahuta NeighborPairs class containing 459 atoms and 372 pairs>
Atom-Plane and Plane-Plane Contacts¶
In [9]:
Copied!
from lahuta.contacts import AtomPlaneContacts, PlanePlaneContacts
# atom-plane contacts
apc = AtomPlaneContacts(ns)
# carbon-pi contacts
apc.carbon_pi()
apc.cation_pi()
from lahuta.contacts import AtomPlaneContacts, PlanePlaneContacts
# atom-plane contacts
apc = AtomPlaneContacts(ns)
# carbon-pi contacts
apc.carbon_pi()
apc.cation_pi()
Out[9]:
<Lahuta NeighborPairs class containing 11 atoms and 6 pairs>
In [10]:
Copied!
# plane-plane contacts
ppc = PlanePlaneContacts(ns)
# plane-plane contacts
results = ppc.compute()
results
# plane-plane contacts
ppc = PlanePlaneContacts(ns)
# plane-plane contacts
results = ppc.compute()
results
Out[10]:
<Lahuta NeighborPairs class containing 53 atoms and 50 pairs>
Computing Contacts¶
Both the Functional and Object-Oriented API described earlier offer a lot of flexibility, but they are also verbose and very expressive.
Lahuta implements interfaces that are easier to use and more concise.
Here we describe the LahutaContacts
class.
In [11]:
Copied!
from lahuta.contacts.computer import LahutaContacts
from lahuta.contacts.computer import LahutaContacts
In [12]:
Copied!
contacts = LahutaContacts()
contacts.compute(ns)
contacts.results
contacts = LahutaContacts()
contacts.compute(ns)
contacts.results
Out[12]:
{'aromatic_neighbors': <Lahuta NeighborPairs class containing 66 atoms and 64 pairs>, 'ionic_neighbors': <Lahuta NeighborPairs class containing 37 atoms and 30 pairs>, 'carbonyl_neighbors': <Lahuta NeighborPairs class containing 14 atoms and 7 pairs>, 'vdw_neighbors': <Lahuta NeighborPairs class containing 206 atoms and 117 pairs>, 'hydrophobic_neighbors': <Lahuta NeighborPairs class containing 459 atoms and 372 pairs>, 'hbond_neighbors': <Lahuta NeighborPairs class containing 0 atoms and 0 pairs>, 'weak_hbond_neighbors': <Lahuta NeighborPairs class containing 0 atoms and 0 pairs>, 'polar_hbond_neighbors': <Lahuta NeighborPairs class containing 359 atoms and 269 pairs>, 'weak_polar_hbond_neighbors': <Lahuta NeighborPairs class containing 306 atoms and 183 pairs>, 'metalic_neighbors': <Lahuta NeighborPairs class containing 0 atoms and 0 pairs>, 'donor_pi': <Lahuta NeighborPairs class containing 26 atoms and 14 pairs>, 'cation_pi': <Lahuta NeighborPairs class containing 11 atoms and 6 pairs>, 'sulphur_pi': <Lahuta NeighborPairs class containing 20 atoms and 14 pairs>, 'carbon_pi': <Lahuta NeighborPairs class containing 109 atoms and 71 pairs>, 'plane_plane_neighbors': <Lahuta NeighborPairs class containing 53 atoms and 50 pairs>}
In [13]:
Copied!
# Only compute atom-plane contacts
contacts = LahutaContacts(contact_type='atom-plane')
contacts.compute(ns)
contacts.results
# Only compute atom-plane contacts
contacts = LahutaContacts(contact_type='atom-plane')
contacts.compute(ns)
contacts.results
Out[13]:
{'donor_pi': <Lahuta NeighborPairs class containing 26 atoms and 14 pairs>, 'cation_pi': <Lahuta NeighborPairs class containing 11 atoms and 6 pairs>, 'sulphur_pi': <Lahuta NeighborPairs class containing 20 atoms and 14 pairs>, 'carbon_pi': <Lahuta NeighborPairs class containing 109 atoms and 71 pairs>}
In [14]:
Copied!
# Remove all built-in contact functions (i.e., we initialize with None)
contacts = LahutaContacts(contact_type=None)
# Register a custom contact function, which is just a function that does not do anything to the input NeighborPairs object
def custom_contact_func(ns):
return ns
contacts.register(custom_contact_func)
# We can also now register specific built-in contact functions (here we register the hydrophobic and van der Waals contacts)
contacts.register([F.hydrophobic_neighbors, F.vdw_neighbors])
contacts.compute(ns)
contacts.results
# Remove all built-in contact functions (i.e., we initialize with None)
contacts = LahutaContacts(contact_type=None)
# Register a custom contact function, which is just a function that does not do anything to the input NeighborPairs object
def custom_contact_func(ns):
return ns
contacts.register(custom_contact_func)
# We can also now register specific built-in contact functions (here we register the hydrophobic and van der Waals contacts)
contacts.register([F.hydrophobic_neighbors, F.vdw_neighbors])
contacts.compute(ns)
contacts.results
Out[14]:
{'custom_contact_func': <Lahuta NeighborPairs class containing 1778 atoms and 2283 pairs>, 'hydrophobic_neighbors': <Lahuta NeighborPairs class containing 459 atoms and 372 pairs>, 'vdw_neighbors': <Lahuta NeighborPairs class containing 206 atoms and 117 pairs>}