Hi @Nicolo-0 ,
We have exposed H-bond functionality in our Python API - now you can generate H-bonds using Python scripting in SAMSON. See SBHydrogenBondGroup, SBHydrogenBond.
You can:
specify for which systems to generate H-bonds
remove H-bonds
add H-bonds
Note: H-bonds are stored within an H-bond group, which itself is stored in a structural model. On the other hand, the Hydrogen Bond Finder provides the results as just a visual model for some historical/performance reasons.
Here is a sample code to add H-bonds based on a structural model or between receptors and ligands (see Python Scripting Guide: Selecting for more information on how to get nodes):
### create H-bonds
# get an indexer of all structural models in the active document
structural_model_indexer = SAMSON.getNodes("node.type structuralModel")
# get the first structural model
structural_model = structural_model_indexer[0]
# get an indexer with receptor and ligand nodes
receptor_indexer = SAMSON.getNodes("node.category receptor")
ligand_indexer = SAMSON.getNodes("node.category ligand")
with SAMSON.holding("Add H-bonds"):
# create an H-bond group object between atoms in a single node indexer
h_bond_group = SBHydrogenBondGroup("H-bonds", structural_model_indexer)
# create an H-bond group object between atoms in two node indexers
#h_bond_group = SBHydrogenBondGroup("H-bonds between receptor and ligand", receptor_indexer, ligand_indexer)
# compute H-bonds
h_bond_group.update()
# hold the node for undo/redo
SAMSON.hold(h_bond_group)
# create the H-bond group
h_bond_group.create()
# add the node to the active document
structural_model.addChild(h_bond_group)
The newly created H-bond group will be placed in the structural model - expand it in the Document view to see it. You can access its options by selecting it and opening the Inspector.
You can remove H-bonds from an H-bond group based on some criteria, e.g., based on the donor-acceptor distance:
### remove some H-bonds from the H-bond group
# get H-bonds from the H-bond group, exclude the H-bond group itself
hbond_indexer = h_bond_group.getNodes("not n.t hbg")
print(f"The total number of computed H-bonds is {len(hbond_indexer)}")
with SAMSON.holding("Remove some H-bonds"):
for hbond in hbond_indexer:
if hbond.donorAcceptorDistance > SBQuantity.angstrom(3.5):
print(hbond)
h_bond_group.removeChild(hbond)
updated_hbond_indexer = h_bond_group.getNodes("not n.t hbg")
print(f"The total number of computed H-bonds is {len(updated_hbond_indexer)}")
You can also add new H-bonds in a H-bond group, as follows:
### add an H-bond in the H-bond group
with SAMSON.holding("Add new H-bonds"):
# create an H-bond object based on already defined acceptor, donor, and (optionally) hydrogen atoms
hbond = SBHydrogenBond(acceptor, donor) #, hydrogen
# hold the node for undo/redo
SAMSON.hold(hbond)
# create the H-bond
hbond.create()
h_bond_group.addChild(hbond)
Let me know if you have any questions or require some help.