Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working moe import lb and other changes #26

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions openad/flask_apps/molviewer/index copy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="css/carbon.css" />
<link rel="stylesheet" href="css/main.css" />
<link rel="stylesheet" href="app/molviewer-main.css" />
<script src="app/3dmol/3Dmol-min.js"></script>
<script src="app/jsmol/JSmol.min.js"></script>
</head>
<body>
<div id="mol-render">
<div class="mol-2d">{{mol_svg | safe}}</div>
<div class="mol-3d"></div>
</div>

<div id="grid">
<!-- <div class="grid grid-1"></div>
<div class="grid grid-2"></div>
<div class="grid grid-3"></div>
<div class="grid grid-4"></div>
<div class="grid grid-5"></div>
<div class="grid grid-6"></div>
<div class="grid grid-7"></div>
<div class="grid grid-8"></div>
<div class="grid grid-9"></div>
<div class="grid grid-10"></div>
<div class="grid grid-11"></div>
<div class="grid grid-12"></div> -->

<!-- Left -->
<div class="col-left">
<!-- <div id="breadcrumbs">Molecules &nbsp;&rsaquo;&nbsp; Ibuprofen.json</div> -->
<div id="title-wrap">
<div class="icn-mol"></div>
<h1 id="data-name" data-val="{{mol.name}}" class="loading">{% if mol.name %}{{mol.name}}{% else %}Unnamed Molecule{% endif %}</h1>
<!-- <div id="btn-bookmark" class="icn-star"></div> -->
</div>
<div id="identification">
<div><b>InChI:</b> <span id="data-inchi">{{mol['properties']['inchi']}}</span></div>
<div><b>InChIKey:</b> <span id="data-inchikey">{{mol['properties']['inchikey']}}</span></div>
<div><b>Canonical SMILES:</b> <span id="data-canonical-smiles">{{mol['properties']['canonical_smiles']}}</span></div>
<div><b>Isomeric SMILES:</b> <span id="data-isomeric-smiles">{{mol['properties']['isomeric_smiles']}}</span></div>
<div>
<b>PubChem CID:</b> {% if mol['properties']['cid'] %}<a id="data-cid" href="https://pubchem.ncbi.nlm.nih.gov/compound/{{mol['properties']['cid']}}" target="_blank">{{mol['properties']['cid']}}</a>{% else %}<span
id="fetching-pubchem"
data-text="Fetching"
>Fetching</span
>{% endif %}
</div>
</div>

<br />
<hr />
<br />

<div id="parameters">
<h2>Parameters</h2>
<div class="param-wrap">
{% for prop in mol['properties'] %}
{% if prop != 'record' %}
<div{% if mol['property_sources'][prop] %} title="{{mol['property_sources'][prop]}}"{% endif %}><b>{{prop}}:</b> {% if mol['properties'][prop] %}{{mol['properties'][prop]}}{% else %}<span class="non-val"></span>{% endif %}</div>
{% endif %}
{% endfor %}
</div>
</div>

<br />
<a class="toggle-expand" id="show-json" href="#">JSON</a>
<pre style="tab-size: 30px">{{mol_json}}</pre>
<br /><br />

<a class="toggle-expand" id="show-json-pubchem" href="#">PubChem Record</a>
<pre style="tab-size: 30px">{{pubchem_json}}</pre>
</div>

<!-- Right -->
<div class="col-right"></div>
</div>
<div id="mol-data" data-sdf="{{mol_sdf}}" data-json="{{mol_json}}"></div>

<script src="app/molviewer-main.js"></script>
</body>
</html>
41 changes: 30 additions & 11 deletions openad/flask_apps/molviewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,58 @@ <h1 id="data-name" data-val="{{mol.name}}" class="loading">{% if mol.name %}{{mo
<!-- <div id="btn-bookmark" class="icn-star"></div> -->
</div>
<div id="identification">
<div><b>InChI:</b> <span id="data-inchi">{{mol['properties']['inchi']}}</span></div>
<div><b>InChIKey:</b> <span id="data-inchikey">{{mol['properties']['inchikey']}}</span></div>
<div><b>Canonical SMILES:</b> <span id="data-canonical-smiles">{{mol['properties']['canonical_smiles']}}</span></div>
<div><b>Isomeric SMILES:</b> <span id="data-isomeric-smiles">{{mol['properties']['isomeric_smiles']}}</span></div>
<div><b>InChI:</b> <span id="data-inchi">{{mol['identifiers']['inchi']}}</span></div>
<div><b>InChIKey:</b> <span id="data-inchikey">{{mol['identifiers']['inchikey']}}</span></div>
<div><b>Canonical SMILES:</b> <span id="data-canonical-smiles">{{mol['identifiers']['canonical_smiles']}}</span></div>
<div><b>Isomeric SMILES:</b> <span id="data-isomeric-smiles">{{mol['identifiers']['isomeric_smiles']}}</span></div>
<div><b>Formula:</b> <span id="data-isomeric-smiles">{{mol['identifiers']['formula']}}</span></div>
<div>
<b>PubChem CID:</b> {% if mol['properties']['cid'] %}<a id="data-cid" href="https://pubchem.ncbi.nlm.nih.gov/compound/{{mol['properties']['cid']}}" target="_blank">{{mol['properties']['cid']}}</a>{% else %}<span
<b>PubChem CID:</b> {% if mol['identifiers']['cid'] %}<a id="data-cid" href="https://pubchem.ncbi.nlm.nih.gov/compound/{{mol['identifiers']['cid']}}" target="_blank">{{mol['identifiers']['cid']}}</a>{% else %}<span
id="fetching-pubchem"
data-text="Fetching"
>Fetching</span
>{% endif %}
</div>
</div>

<br />
<hr />
<br />

<div id="synonyms">
<h2>Synonyms</h2>
<div class="synonyms-wrap">
{% for synonym in mol['synonyms'] %}
{{synonym}}<br/>
{% endfor %}
</div>
</div>

<br />
<hr />
<br />

<div id="parameters">
<h2>Parameters</h2>
<div class="param-wrap">
{% for prop in mol['properties'] %}
{% if prop != 'record' %}
<div{% if mol['property_sources'][prop] %} title="{{mol['property_sources'][prop]}}"{% endif %}><b>{{prop}}:</b> {% if mol['properties'][prop] %}{{mol['properties'][prop]}}{% else %}<span class="non-val"></span>{% endif %}</div>
{% endif %}
{% endfor %}
</div>
</div>

<br />
<hr />
<br />

<div id="analysis">
<h2>Analysis</h2>
Comin soon...
</div>

<br />
<a class="toggle-expand" id="show-json" href="#">JSON</a>
<pre style="tab-size: 30px">{{mol_json}}</pre>
<br /><br />

<a class="toggle-expand" id="show-json-pubchem" href="#">PubChem Record</a>
<pre style="tab-size: 30px">{{pubchem_json}}</pre>
</div>

<!-- Right -->
Expand Down
13 changes: 12 additions & 1 deletion openad/flask_apps/molviewer/molviewer-main.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,19 @@ body {
* TEMP
*/

#parameters div {
#parameters .param-wrap {
display: flex;
flex-wrap: wrap;
}

#parameters .param-wrap div {
margin-bottom: 4px;
padding-right: 20px;
width: 25%;
box-sizing: border-box;
}
#synonyms .synonyms-wrap {
column-count: 4;
}

pre {
Expand Down
6 changes: 4 additions & 2 deletions openad/flask_apps/molviewer/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@


def fetchRoutesMolViewer(cmd_pointer, mol, mol_sdf, mol_svg):
from openad.molecules.mol_functions import organize_properties

mol_json = json.dumps(mol, indent="\t")
pubchem_json = {}

def main():
_stringify_prop_sources(mol)
return render_template(
"/molviewer/index.html",
mol=mol,
mol=organize_properties(mol),
mol_json=mol_json,
pubchem_json=pubchem_json,
mol_sdf=mol_sdf,
Expand All @@ -28,7 +30,7 @@ def enrich():
_stringify_prop_sources(mol)
html = render_template(
"/molviewer/index.html",
mol=mol,
mol=organize_properties(mol),
mol_json=mol_json,
pubchem_json=pubchem_json,
mol_sdf=mol_sdf,
Expand Down
14 changes: 14 additions & 0 deletions openad/helpers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,20 @@ def print_separator(style=None, width=None, return_val=False):
return output_text(f"{'-' * width}", nowrap=True, return_val=return_val)


# Load a module or a module's function from a toolkit folder.
def load_tk_module(cmd_pointer, toolkit_name, lib_name, func_name=None):
import importlib.util as ilu

folder = cmd_pointer.toolkit_dir + f"/{toolkit_name}/{lib_name}.py"
spec = ilu.spec_from_file_location(lib_name, folder)
module = ilu.module_from_spec(spec)
spec.loader.exec_module(module)
if func_name:
return getattr(module, func_name)
else:
return module


#
#
#
Expand Down
14 changes: 4 additions & 10 deletions openad/molecules/mol_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ def get_molecule_data(cmd_pointer, molecule_identifier):
Used to enrich the molecule data from the molecule viewer Flask app.
"""

from openad.molecules.mol_commands import retrieve_mol_from_list, retrieve_mol, get_identifiers, get_properties

return_dict = {}
from openad.molecules.mol_commands import retrieve_mol_from_list, retrieve_mol

mol = retrieve_mol_from_list(cmd_pointer, molecule_identifier)

if mol is None:
mol = retrieve_mol(molecule_identifier)
if mol is not None:
cmd_pointer.last_external_molecule = mol.copy()
return mol
# # cmd_pointer.last_external_molecule = mol.copy()
# return_dict["smiles"] = get_identifiers(mol)["canonical_smiles"]
# return_dict["identifiers"] = get_identifiers(mol)
# return_dict["properties"] = get_properties(mol)
# return_dict["synonyms"] = mol["synonyms"]["Synonym"]
# return_dict["analysis"] = mol["analysis"]
# return return_dict
# return organize_properties(mol)

else:
return None
10 changes: 5 additions & 5 deletions openad/molecules/mol_batch_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from openad.molecules.mol_functions import (
merge_molecule_properties,
valid_smiles,
new_molecule_TRASH,
new_molecule,
canonical_smiles,
)
from openad.molecules.mol_commands import retrieve_mol_from_list, add_molecule
Expand All @@ -29,7 +29,7 @@ def load_batch_molecules(cmd_pointer, inp):
if "pubchem_merge" in inp.as_dict():
batch_pubchem(cmd_pointer, mol_dataframe)
if mol_dataframe is not None:
shred_merge_add_Dataframe_mols(mol_dataframe, cmd_pointer)
shred_merge_add_df_mols(mol_dataframe, cmd_pointer)
return True


Expand Down Expand Up @@ -87,8 +87,8 @@ def __init__(self):
batch_spinner.stop()


def shred_merge_add_Dataframe_mols(dataframe, cmd_pointer):
"""shreds the molecule relevent propoerties from data frame and loads into molecules"""
def shred_merge_add_df_mols(dataframe, cmd_pointer):
"""shreds the molecule relevent properties from dataframe and loads into molecules"""
dict_list = dataframe.to_dict("records")
for a_mol in dict_list:
Name_Flag = False
Expand Down Expand Up @@ -121,7 +121,7 @@ def shred_merge_add_Dataframe_mols(dataframe, cmd_pointer):
if merge_mol is None:
if name is None:
name = a_mol["SMILES"]
merge_mol = new_molecule_TRASH(name, a_mol["SMILES"])
merge_mol = new_molecule(a_mol["SMILES"], name)
if merge_mol is not None:
merge_mol = merge_molecule_properties(a_mol, merge_mol)
else:
Expand Down
Loading