# GlobalChem

First initialize the class must be initialized:

```
gc = GlobalChem()
```

**Print the Network**

{% tabs %}
{% tab title="Code" %}

```
gc.print_globalchem_network()
```

{% endtab %}

{% tab title="Output" %}

```

                                ┌solvents─common_organic_solvents
             ┌organic_synthesis─└protecting_groups─amino_acid_protecting_groups
             │          ┌polymers─common_monomer_repeating_units
             ├materials─└clay─montmorillonite_adsorption
             │                            ┌privileged_kinase_inhibtors
             │                            ├privileged_scaffolds
             ├proteins─kinases─┌scaffolds─├iupac_blue_book_substituents
             │                 │          └common_r_group_replacements
             │                 └braf─inhibitors
             │              ┌vitamins
             │              ├open_smiles
             ├miscellaneous─├amino_acids
             │              └regex_patterns
global_chem──├environment─emerging_perfluoroalkyls
             │          ┌schedule_one
             │          ├schedule_four
             │          ├schedule_five
             ├narcotics─├pihkal
             │          ├schedule_two
             │          └schedule_three
             ├interstellar_space
             │                    ┌cannabinoids
             │                    │         ┌electrophillic_warheads_for_kinases
             │                    ├warheads─└common_warheads_covalent_inhibitors
             └medicinal_chemistry─│      ┌phase_2_hetereocyclic_rings
                                  └rings─├iupac_blue_book_rings
                                         └rings_in_drugs
                                         
```

{% endtab %}
{% endtabs %}

**Check the available nodes in GlobalChem:**

{% tabs %}
{% tab title="Code" %}

```
nodes_list = gc.check_available_nodes()
print (nodes_list)
```

{% endtab %}

{% tab title="Output" %}

```
'emerging_perfluoro_alkyls', 
'montmorillonite_adsorption', 
'common_monomer_repeating_units',
 'electrophilic_warheads_for_kinases',
```

{% endtab %}
{% endtabs %}

**Retrieve all the Nodes**

{% tabs %}
{% tab title="Code" %}

```
nodes_list = gc.get_all_nodes()
```

{% endtab %}
{% endtabs %}

**Get the Tree Depth of GlobalChem**

{% tabs %}
{% tab title="Code" %}

```
depth = gc.get_depth_of_globalchem()
```

{% endtab %}
{% endtabs %}

**Get GlobalChem All Nodes SMILES**

{% tabs %}
{% tab title="Code" %}

```
depth = gc.get_all_smiles()
```

{% endtab %}
{% endtabs %}

**Get GlobalChem All Nodes SMARTS**

{% tabs %}
{% tab title="Code" %}

```
depth = gc.get_all_smarts()
```

{% endtab %}
{% endtabs %}

**Get GlobalChem All Nodes Names**

{% tabs %}
{% tab title="Code" %}

```
depth = gc.get_all_names()
```

{% endtab %}
{% endtabs %}

**Get SMILES Definition by IUPAC Name**

This function fetches the distance between two words using the Levenshtein distance with a distance tolerance number. It removes both grammar and upper case letters automatically and tries to match the best fitting word against the query and return their dedicated paths. Users have the option to return the exact definition or partial definitions.&#x20;

{% tabs %}
{% tab title="Code" %}

```
definition = gc.get_smiles_by_iupac(
    'benzene',   
    distance_tolerance=7,
    return_partial_definitions=True                       
)
print (definition)
```

{% endtab %}

{% tab title="Output" %}

```
[{'methylbenzoate': 'c1ccc(C(=O)OC)cc1', 'network_path': 'global_chem.medicinal_chemistry.scaffolds.common_r_group_replacements', 'levenshtein_distance': 7}]
```

{% endtab %}
{% endtabs %}

You have the option to do a fuzzy reconstruction of the SMILES from the IUPAC used stripped grammar and functional groups:

{% tabs %}
{% tab title="Code" %}

```
definition = gc.get_smiles_by_iupac(
        '(4R,4aR,7S,7aR,12bS)-3-methyl-2,4,4a,7,7a,13-hexahydro-1H-4,12-methanobenzofuro[3,2-e]isoquinoline-7,9-diol',
        distance_tolerance=2,
        return_partial_definitions=False,
        reconstruct_smiles=True,
)

print (definition)
```

{% endtab %}

{% tab title="Output" %}

```
C12=C(C=NC=C2)C=CC=C1.C12=C(C=NC=C2)C=CC=C1.[CH2]CCCCCCCCCCCCCCC.[CH2]C.[CH3].SC.c1cncc2ccccc12.C12=CC=CC=C1C=NC=C2.C.CC.C[C@H]1[C@H](C(C)C)CC[C@@H](C)C1.[CH3].S
```

{% endtab %}
{% endtabs %}

**Build the GlobalChem Network and Print it Out**

{% tabs %}
{% tab title="Code" %}

```
gc.build_global_chem_network(
    print_output=True,          # Print the network out
    debugger=False,             # For Developers mostly to see all node values
)
```

{% endtab %}

{% tab title="Output" %}

```
'global_chem': {
    'children': [
        'environment',
        'miscellaneous',
        'organic_synthesis',
        'medicinal_chemistry',
        'narcotics',
        'interstellar_space',
        'proteins',
        'materials'
    ],
    'name': 'global_chem',
    'node_value': <global_chem.global_chem.Node object at 0x10f60eed0>,
    'parents': []
},
```

{% endtab %}
{% endtabs %}

The algorithm uses a series of parents/children to connect nodes instead of "edges" as in traditional graph networks. This just makes it easier to code if the graph database lives as a 1-dimensional with lists of parents and children's connected in this fashion.

**Fetch a Node**

{% tabs %}
{% tab title="Code" %}

```
gc = GlobalChem()
gc.build_global_chem_network()
node = gc.get_node('emerging_perfluoroalkyls')
print (node)
```

{% endtab %}

{% tab title="Output" %}

```
{
    'node_value': <global_chem.global_chem.Node object at 0x117fee210>, 
    'children': [], 
    'parents': ['emerging_perfluoroalkyls'], 
    'name': 'emerging_perfluoroalkyls'
}
```

{% endtab %}
{% endtabs %}

**Fetch the IUPAC:SMILES/SMARTS Data from the Node**

{% tabs %}
{% tab title="Code" %}

```
gc = GlobalChem()
gc.build_global_chem_network()
smiles = gc.get_node_smiles('emerging_perfluoroalkyls')
smarts = gc.get_node_smarts('emerging_perfluoroalkyls')

print ("Length of Perfluoroalkyls: %s " % len(smiles))
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Code" %}

```
from global_chem import GlobalChem

gc = GlobalChem(verbose=False)
gc.initiate_network()
gc.add_node('global_chem', 'common_monomer_repeating_units')
gc.add_node('common_monomer_repeating_units','electrophilic_warheads_for_kinases')
values = gc.get_node_smiles('common_monomer_repeating_units')

print (values)
```

{% endtab %}

{% tab title="Output" %}

```
'3′-bromo-2-chloro[1,1′:4′,1′′-terphenyl]-4,4′′':
 'ClC1=CC=CC=C1C2=CC=C(C3=CC=CC=C3)C(Br)=C2'

```

{% endtab %}
{% endtabs %}

**Creating a Deep Layer Chemical Graph Networks (DGN) & Print it Out:**

This is for the more advanced users of building networks and how to manage sets of layers.&#x20;

{% tabs %}
{% tab title="Code" %}

```
# Create a Deep Layer Network

gc = GlobalChem()
gc.initiate_deep_layer_network()
gc.add_deep_layer(
    [
        'emerging_perfluoroalkyls',
        'montmorillonite_adsorption',
        'common_monomer_repeating_units'
    ]
)
gc.add_deep_layer(
    [
        'common_warheads_covalent_inhibitors',
        'privileged_scaffolds',
        'iupac_blue_book'
    ]
)

gc.print_deep_network()
```

{% endtab %}

{% tab title="Output" %}

```
                                      ┌common_warhead_covalent_inhibitors
            ┌emerging_perfluoroalkyls─├privileged_scaffolds
            │                         └iupac_blue_book
            │                           ┌common_warhead_covalent_inhibitors
global_chem─├montmorillonite_adsorption─├privileged_scaffolds
            │                           └iupac_blue_book
            │                               ┌common_warhead_covalent_inhibitors
            └common_monomer_repeating_units─├privileged_scaffolds
                                            └iupac_blue_book

```

{% endtab %}
{% endtabs %}

**Compute a Common Score**

Common Score Algorithm:

1. Datamine the current graph network of GlobalChem
2. Get the object weights of each mention&#x20;
3. Determine the mention weight
4. Sum the Weight's and that is how common the molecule is.&#x20;

The higher the value the higher the common score tied with it's IUPAC name.&#x20;

{% tabs %}
{% tab title="Code" %}

```
gc = GlobalChem()
gc.build_global_chem_network(print_output=False, debugger=False)
gc.compute_common_score('benzene', verbose=True)
```

{% endtab %}

{% tab title="Output" %}

```
GlobalChem Common Score: 7.139921294271971
```

{% endtab %}
{% endtabs %}

**To TSV**

The network returned in all CSV format for interoperability for web application development mostly but can also be used to search.&#x20;

{% tabs %}
{% tab title="Code" %}

```
gc = GlobalChem()
gc.to_tsv('global_chem.tsv')
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://globalchem.gitbook.io/globalchem-your-chemical-graph-network/api/globalchem.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
