<jupyter_start><jupyter_text>Molecules and Sites In `wc_rules`, the basic building blocks are molecules and sites.<jupyter_code>from wc_rules.chem2 import Molecule,Site<jupyter_output><empty_output><jupyter_text>To **define types of molecules and sites**, subclass them from `chem2.Molecule` and `chem2.Site` respectively. Additional subclassing is allowed, so each molecule/site type is actually a class hierarchy. Below we create the molecule hierarchy `Molecule -> Receptor -> EGFR`<jupyter_code>class Receptor(Molecule):pass
class EGFR(Receptor):pass<jupyter_output><empty_output><jupyter_text>Similarly, from `Site`, we create 4 different types of sites.<jupyter_code>class LigandBindingSite(Site):pass
class DimerizationSite(Site):pass
class TyrosineMotif(Site):pass<jupyter_output><empty_output><jupyter_text>To **create instances of molecules and sites**, simply call their constructors, optionally with an `id` attribute.<jupyter_code># Creating receptor molecules
R1 = EGFR()
R1 = EGFR(id='R1')
print(R1)<jupyter_output><__main__.EGFR: R1><jupyter_text>We recommend using **`set_id(id)`** and **`get_id()`** for `id` attribute.<jupyter_code>R1 = EGFR().set_id('R1')
print(R1.get_id())<jupyter_output>R1<jupyter_text>Instances can **type-checked** against any superclass.<jupyter_code>check01 = isinstance(R1,EGFR)
check02 = isinstance(R1,Receptor)
check03 = isinstance(R1,Molecule)
print(check01 and check02 and check03)<jupyter_output>True<jupyter_text>Here, we create one instance each of `LigandBindingSite` and `DimerizationSite` and two instances of `TyrosineMotif`.<jupyter_code># Creating sites
L = LigandBindingSite().set_id('L')
D = DimerizationSite().set_id('D')
Y1 = TyrosineMotif().set_id('Y1')
Y2 = TyrosineMotif().set_id('Y2')<jupyter_output><empty_output><jupyter_text>A molecule may have multiple sites (stored as a list on `sites` attribute), but a site may have only one molecule (stored as a reference on `molecule` attribute). To **attach sites to molecules**, one may equivalently use **`add_sites(*args)`** or **`set_molecule(arg)`** on the respective instances. Here we add the site instances `L,D,Y1,Y2` to the molecule instance `R1`.<jupyter_code># Assigning sites to a molecule
R1.add_sites(L,D)
Y1.set_molecule(R1)
Y2.set_molecule(R1)

print([x.get_id() for x in R1.sites])
print([x.molecule.get_id() for x in [L,D,Y1,Y2]])<jupyter_output>['L', 'D', 'Y1', 'Y2']
['R1', 'R1', 'R1', 'R1']<jupyter_text>Similarly, to **detach sites from molecules**, one may equivalently use **`remove_sites(*args)`** or **`unset_molecule()`** on the respective instances.<jupyter_code>R1.remove_sites(L,D)
Y1.unset_molecule()
Y2.unset_molecule()

print(R1.sites)<jupyter_output>[]<jupyter_text>To simultaneously create the molecule instance, all 4 site instances and assign the sites to the molecule, one can do:<jupyter_code>R1 = EGFR(id='R1').add_sites(
    LigandBindingSite(id='L'),
    DimerizationSite(id='D'),
    TyrosineMotif(id='Y1'),
    TyrosineMotif(id='Y2')
)

print([x.get_id() for x in R1.sites])<jupyter_output>['L', 'D', 'Y1', 'Y2']<jupyter_text>To **access the sites on a molecule**, we recommend using __`get_sites(**kwargs)`__, which allows filtering the results based on scalar attribute or class types. To access a site's molecule, use **`get_molecule()`**.<jupyter_code>site_list = R1.get_sites()
print([x.get_id() for x in site_list])
print([x.get_molecule().get_id() for x in site_list])

site_list = R1.get_sites(site_type=TyrosineMotif)
print([x.get_id() for x in site_list])
     
site_list = R1.get_sites(site_type=LigandBindingSite)
print([x.get_id() for x in site_list])
     
site_list = R1.get_sites(site_type=TyrosineMotif,id='Y2')
print([x.get_id() for x in site_list])<jupyter_output>['L', 'D', 'Y1', 'Y2']
['R1', 'R1', 'R1', 'R1']
['Y1', 'Y2']
['L']
['Y2']
{'fraction_non_alphanumeric': 0.14716684155299056, 'fraction_numerical': 0.019674711437565582, 'mean_word_length': 7.54932735426009, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '595321', 'license': 'MIT', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1379, 'n_words': 344, 'path': 'notebooks/wc_rules/Example 1-01 Molecules and Sites.ipynb', 'repo_name': 'saapooch/wc-jupyter', 'size': '3812'}