Skip to content

Commit

Permalink
Modified available_to_bind to allowed_to_bind. Added to Example 1-02.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsekar committed May 11, 2018
1 parent a1bae8e commit d8b3a63
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
61 changes: 49 additions & 12 deletions examples/Example 1-02 Bonds.ipynb
Expand Up @@ -24,9 +24,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"from wc_rules.chem2 import Molecule,Site,Bond"
Expand All @@ -35,9 +33,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class Rec(Molecule):pass\n",
Expand All @@ -62,9 +58,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"rec1 = Lig1.get_sites(id='rec1')[0]\n",
Expand Down Expand Up @@ -167,9 +161,7 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class TetramerBond(Bond):\n",
Expand Down Expand Up @@ -238,6 +230,51 @@
"except:\n",
" print('Not allowed.')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To **disallow a site type from binding**, one can set the `allowed_to_bind` attribute during subclassing. "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Allowed.\n",
"Not allowed.\n"
]
}
],
"source": [
"class Site1(Site):\n",
" pass\n",
"class Site2(Site):\n",
" allowed_to_bind = False\n",
" \n",
"x1 = Site1()\n",
"x2 = Site2()\n",
"bnd = Bond().add_targets(x1,x2)\n",
"for site in [x1,x2]:\n",
" try:\n",
" site.verify_allowed_to_bind()\n",
" print('Allowed.')\n",
" except:\n",
" print('Not allowed.')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
8 changes: 5 additions & 3 deletions wc_rules/chem2.py
Expand Up @@ -28,7 +28,7 @@ def remove_sites(self,*args):
class Site(entity.Entity):
molecule = core.ManyToOneAttribute(Molecule,related_name='sites')
allowed_molecule_types = None
available_to_bind = True
allowed_to_bind = True

# Setters
def set_molecule(self,molecule):
Expand Down Expand Up @@ -84,8 +84,10 @@ def verify_maximum_allowed_relations_as_a_target(self):
raise utils.ValidateError('Maximum number of relations of the same type allowed for this target site exceeded.')
return

def verify_available_to_bind(self):
return self.available_to_bind
def verify_allowed_to_bind(self):
if not self.allowed_to_bind:
raise utils.ValidateError('This site is not allowed to have a bond.')
return

class SiteRelation(entity.Entity):
sources = core.ManyToManyAttribute(Site,related_name='site_relations_sources')
Expand Down

0 comments on commit d8b3a63

Please sign in to comment.