Upload 1548 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +12 -0
- Dockerfile +18 -0
- app.py +45 -0
- deepchem/.DS_Store +0 -0
- deepchem/mcp_output/README_MCP.md +118 -0
- deepchem/mcp_output/analysis.json +0 -0
- deepchem/mcp_output/diff_report.md +150 -0
- deepchem/mcp_output/mcp_plugin/__init__.py +0 -0
- deepchem/mcp_output/mcp_plugin/adapter.py +481 -0
- deepchem/mcp_output/mcp_plugin/main.py +13 -0
- deepchem/mcp_output/mcp_plugin/mcp_service.py +240 -0
- deepchem/mcp_output/requirements.txt +13 -0
- deepchem/mcp_output/start_mcp.py +30 -0
- deepchem/mcp_output/workflow_summary.json +251 -0
- deepchem/source/.DS_Store +0 -0
- deepchem/source/.pre-commit-config.yaml +25 -0
- deepchem/source/.readthedocs.yml +23 -0
- deepchem/source/.yapfignore +2 -0
- deepchem/source/CODE_OF_CONDUCT.md +46 -0
- deepchem/source/CONTRIBUTING.md +188 -0
- deepchem/source/LICENSE +7 -0
- deepchem/source/README.md +159 -0
- deepchem/source/__init__.py +4 -0
- deepchem/source/contrib/DeepMHC/__init__.py +1 -0
- deepchem/source/contrib/DeepMHC/bd13_datasets.py +150 -0
- deepchem/source/contrib/DeepMHC/deepmhc.py +107 -0
- deepchem/source/contrib/DeepMHC/run_deepmhc.py +41 -0
- deepchem/source/contrib/DiabeticRetinopathy/__init__.py +1 -0
- deepchem/source/contrib/DiabeticRetinopathy/data.py +107 -0
- deepchem/source/contrib/DiabeticRetinopathy/model.py +252 -0
- deepchem/source/contrib/DiabeticRetinopathy/run.py +43 -0
- deepchem/source/contrib/__init__.py +1 -0
- deepchem/source/contrib/atomicconv/__init__.py +1 -0
- deepchem/source/contrib/atomicconv/acnn/__init__.py +1 -0
- deepchem/source/contrib/atomicconv/acnn/core/__init__.py +1 -0
- deepchem/source/contrib/atomicconv/acnn/core/get_acnn_core.sh +4 -0
- deepchem/source/contrib/atomicconv/acnn/core/opt_random.py +119 -0
- deepchem/source/contrib/atomicconv/acnn/core/opt_random_tensorgraph.py +73 -0
- deepchem/source/contrib/atomicconv/acnn/core/opt_scaffold.py +119 -0
- deepchem/source/contrib/atomicconv/acnn/core/opt_stratified.py +119 -0
- deepchem/source/contrib/atomicconv/acnn/core/opt_temporal.py +119 -0
- deepchem/source/contrib/atomicconv/acnn/core/tensor_graph_hyper_param_eval.py +116 -0
- deepchem/source/contrib/atomicconv/acnn/core/tensor_graph_hyper_param_search.py +117 -0
- deepchem/source/contrib/atomicconv/acnn/refined/__init__.py +1 -0
- deepchem/source/contrib/atomicconv/acnn/refined/get_acnn_refined.sh +4 -0
- deepchem/source/contrib/atomicconv/acnn/refined/opt_random.py +125 -0
- deepchem/source/contrib/atomicconv/acnn/refined/opt_scaffold.py +125 -0
- deepchem/source/contrib/atomicconv/acnn/refined/opt_stratified.py +125 -0
- deepchem/source/contrib/atomicconv/acnn/refined/opt_temporal.py +125 -0
- deepchem/source/contrib/atomicconv/acnn/refined/tensor_graph_hyper_param_eval.py +137 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,15 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
deepchem/source/contrib/dragonn/tutorial_images/dnn_figure.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
deepchem/source/contrib/dragonn/tutorial_images/sequence_simulations.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
deepchem/source/examples/notebooks/assets/GraphConvArch.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
deepchem/source/examples/notebooks/assets/lime_dog.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
deepchem/source/examples/tutorials/assets/adc_components.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
deepchem/source/examples/tutorials/assets/ADCNet_2.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
deepchem/source/examples/tutorials/assets/generations_adc.jpg filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
deepchem/source/examples/tutorials/assets/lime_dog.png filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
deepchem/source/examples/tutorials/assets/trident_chemwidgets_data/Histogram.png filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
deepchem/source/examples/tutorials/assets/trident_chemwidgets_data/InteractiveMolecule.png filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
deepchem/source/examples/tutorials/assets/trident_chemwidgets_data/JSME.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
deepchem/source/examples/tutorials/assets/trident_chemwidgets_data/Scatter.png filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
RUN useradd -m -u 1000 user && python -m pip install --upgrade pip
|
| 4 |
+
USER user
|
| 5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY --chown=user . /app
|
| 13 |
+
ENV MCP_TRANSPORT=http
|
| 14 |
+
ENV MCP_PORT=7860
|
| 15 |
+
|
| 16 |
+
EXPOSE 7860
|
| 17 |
+
|
| 18 |
+
CMD ["python", "deepchem/mcp_output/start_mcp.py"]
|
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
mcp_plugin_path = os.path.join(os.path.dirname(__file__), "deepchem", "mcp_output", "mcp_plugin")
|
| 6 |
+
sys.path.insert(0, mcp_plugin_path)
|
| 7 |
+
|
| 8 |
+
app = FastAPI(
|
| 9 |
+
title="Deepchem MCP Service",
|
| 10 |
+
description="Auto-generated MCP service for deepchem",
|
| 11 |
+
version="1.0.0"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
@app.get("/")
|
| 15 |
+
def root():
|
| 16 |
+
return {
|
| 17 |
+
"service": "Deepchem MCP Service",
|
| 18 |
+
"version": "1.0.0",
|
| 19 |
+
"status": "running",
|
| 20 |
+
"transport": os.environ.get("MCP_TRANSPORT", "http")
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
@app.get("/health")
|
| 24 |
+
def health_check():
|
| 25 |
+
return {"status": "healthy", "service": "deepchem MCP"}
|
| 26 |
+
|
| 27 |
+
@app.get("/tools")
|
| 28 |
+
def list_tools():
|
| 29 |
+
try:
|
| 30 |
+
from mcp_service import create_app
|
| 31 |
+
mcp_app = create_app()
|
| 32 |
+
tools = []
|
| 33 |
+
for tool_name, tool_func in mcp_app.tools.items():
|
| 34 |
+
tools.append({
|
| 35 |
+
"name": tool_name,
|
| 36 |
+
"description": tool_func.__doc__ or "No description available"
|
| 37 |
+
})
|
| 38 |
+
return {"tools": tools}
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return {"error": f"Failed to load tools: {str(e)}"}
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
import uvicorn
|
| 44 |
+
port = int(os.environ.get("PORT", 7860))
|
| 45 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|
deepchem/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
deepchem/mcp_output/README_MCP.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DeepChem MCP (Model Context Protocol) Service README
|
| 2 |
+
|
| 3 |
+
## 1) Project Introduction
|
| 4 |
+
|
| 5 |
+
This MCP (Model Context Protocol) service wraps core DeepChem capabilities for molecular ML workflows, including:
|
| 6 |
+
|
| 7 |
+
- Dataset loading and preprocessing (CSV/SDF/JSON/image/biological sequence)
|
| 8 |
+
- Featurization (ECFP, graph, SMILES/token, protein/complex features)
|
| 9 |
+
- Model training/inference (Torch, TensorFlow, JAX, sklearn, XGBoost)
|
| 10 |
+
- Benchmarking via MolNet loaders and benchmark runners
|
| 11 |
+
- Evaluation, metrics, splitting, transforms, and utility workflows
|
| 12 |
+
|
| 13 |
+
Repository: https://github.com/deepchem/deepchem
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## 2) Installation
|
| 18 |
+
|
| 19 |
+
### Base requirements
|
| 20 |
+
- Python 3.8+ (recommended 3.10/3.11)
|
| 21 |
+
- Core libs: `numpy scipy pandas scikit-learn joblib tqdm`
|
| 22 |
+
|
| 23 |
+
Install core package:
|
| 24 |
+
- `pip install deepchem`
|
| 25 |
+
|
| 26 |
+
Install optional stacks as needed:
|
| 27 |
+
- Chemistry: `rdkit`
|
| 28 |
+
- Deep learning: `torch` or `tensorflow` or `jax`
|
| 29 |
+
- Extras: `pytorch-lightning transformers dgl torch-geometric xgboost lightgbm pyscf`
|
| 30 |
+
|
| 31 |
+
Practical setup pattern:
|
| 32 |
+
1. Create a fresh virtual environment
|
| 33 |
+
2. Install `deepchem`
|
| 34 |
+
3. Add only the backend/features you need (Torch/TensorFlow/JAX + RDKit)
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## 3) Quick Start
|
| 39 |
+
|
| 40 |
+
### Typical MCP (Model Context Protocol) flow
|
| 41 |
+
1. Load dataset from MolNet (e.g., Tox21, Delaney, QM9)
|
| 42 |
+
2. Apply featurizer and split strategy
|
| 43 |
+
3. Train selected model
|
| 44 |
+
4. Evaluate with DeepChem metrics
|
| 45 |
+
5. Return scores/predictions via MCP (Model Context Protocol) response
|
| 46 |
+
|
| 47 |
+
### Example task patterns
|
| 48 |
+
- Classification benchmark: use `deepchem.molnet.run_benchmark`
|
| 49 |
+
- Low-data benchmark: use `deepchem.molnet.run_benchmark_low_data`
|
| 50 |
+
- Programmatic loading: use `deepchem.molnet.load_function.*`
|
| 51 |
+
- Data ingest: `deepchem.data.*` loaders
|
| 52 |
+
- Feature extraction: `deepchem.feat.*`
|
| 53 |
+
- Training APIs: `deepchem.models.*` / `deepchem.models.torch_models.*`
|
| 54 |
+
- Evaluation: `deepchem.metrics.*`, `deepchem.utils.evaluate`
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
|
| 58 |
+
## 4) Available Tools and Endpoints
|
| 59 |
+
|
| 60 |
+
Recommended MCP (Model Context Protocol) service endpoints:
|
| 61 |
+
|
| 62 |
+
- `health_check`
|
| 63 |
+
- Verify runtime, backend availability, and import status.
|
| 64 |
+
|
| 65 |
+
- `list_capabilities`
|
| 66 |
+
- Return installed backends/features (Torch/TF/JAX/RDKit, etc.).
|
| 67 |
+
|
| 68 |
+
- `load_dataset`
|
| 69 |
+
- Load datasets via MolNet (`load_tox21`, `load_delaney`, `load_qm9`, etc.) or file loaders.
|
| 70 |
+
|
| 71 |
+
- `featurize_data`
|
| 72 |
+
- Apply selected featurizer (ECFP, graph conv, SMILES tokenizer, protein/complex, material).
|
| 73 |
+
|
| 74 |
+
- `split_dataset`
|
| 75 |
+
- Apply splitters (random, scaffold, stratified, time/PDBBind, task-based).
|
| 76 |
+
|
| 77 |
+
- `train_model`
|
| 78 |
+
- Train model families (GraphConv, MPNN, GCN/GAT, multitask MLP, sklearn, GBDT).
|
| 79 |
+
|
| 80 |
+
- `predict`
|
| 81 |
+
- Run inference on prepared datasets.
|
| 82 |
+
|
| 83 |
+
- `evaluate_model`
|
| 84 |
+
- Compute metrics (ROC-AUC, PRC-AUC, RMSE, MAE, Pearson R², etc.).
|
| 85 |
+
|
| 86 |
+
- `run_benchmark`
|
| 87 |
+
- Execute MolNet benchmark workflow using selected model/split/featurizer.
|
| 88 |
+
|
| 89 |
+
- `run_low_data_benchmark`
|
| 90 |
+
- Execute low-data benchmark variants.
|
| 91 |
+
|
| 92 |
+
- `export_results`
|
| 93 |
+
- Save predictions, scores, and metadata to disk/artifact storage.
|
| 94 |
+
|
| 95 |
+
---
|
| 96 |
+
|
| 97 |
+
## 5) Common Issues and Notes
|
| 98 |
+
|
| 99 |
+
- Dependency complexity is medium/high; install only required optional stacks.
|
| 100 |
+
- RDKit is essential for many molecule features and loaders.
|
| 101 |
+
- Torch/TF/JAX features are backend-specific; missing backend causes import/runtime failures.
|
| 102 |
+
- Some benchmark datasets require downloading large files; expect longer setup times.
|
| 103 |
+
- GPU acceleration depends on correct CUDA/backend build compatibility.
|
| 104 |
+
- DGL/PyG-based models need matching versions with your PyTorch installation.
|
| 105 |
+
- For reproducibility, set random seeds and pin package versions.
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## 6) References
|
| 110 |
+
|
| 111 |
+
- DeepChem repository: https://github.com/deepchem/deepchem
|
| 112 |
+
- Main package docs (in repo): `README.md`, `docs/`
|
| 113 |
+
- Examples: `examples/`
|
| 114 |
+
- MolNet loaders: `deepchem/molnet/load_function/`
|
| 115 |
+
- Benchmarks:
|
| 116 |
+
- `python -m deepchem.molnet.run_benchmark`
|
| 117 |
+
- `python -m deepchem.molnet.run_benchmark_low_data`
|
| 118 |
+
- Contribution guide: `CONTRIBUTING.md`
|
deepchem/mcp_output/analysis.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
deepchem/mcp_output/diff_report.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Difference Report — `deepchem`
|
| 2 |
+
|
| 3 |
+
**Generated:** 2026-03-14 11:47:54
|
| 4 |
+
**Repository:** `deepchem`
|
| 5 |
+
**Project Type:** Python library
|
| 6 |
+
**Scope:** Basic functionality
|
| 7 |
+
**Change Intrusiveness:** None
|
| 8 |
+
**Workflow Status:** ✅ Success
|
| 9 |
+
**Test Status:** ❌ Failed
|
| 10 |
+
**Files Changed:** 8 added, 0 modified, 0 deleted
|
| 11 |
+
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
## 1) Project Overview
|
| 15 |
+
|
| 16 |
+
This update introduces **8 new files** without modifying existing code, indicating a **non-intrusive additive change set**. The CI/workflow completed successfully, but test execution failed, signaling potential issues in test configuration, environment compatibility, or missing integration logic for newly added assets.
|
| 17 |
+
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
## 2) High-Level Difference Summary
|
| 21 |
+
|
| 22 |
+
| Metric | Value |
|
| 23 |
+
|---|---|
|
| 24 |
+
| New files | 8 |
|
| 25 |
+
| Modified files | 0 |
|
| 26 |
+
| Deleted files | 0 |
|
| 27 |
+
| Intrusiveness | None (additive only) |
|
| 28 |
+
| Workflow result | Success |
|
| 29 |
+
| Test result | Failed |
|
| 30 |
+
|
| 31 |
+
**Interpretation:**
|
| 32 |
+
- The change is structurally safe (no in-place modifications), reducing regression risk for existing core paths.
|
| 33 |
+
- The failed test status is the primary release blocker.
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## 3) Difference Analysis
|
| 38 |
+
|
| 39 |
+
### What changed
|
| 40 |
+
- Added 8 files to the repository.
|
| 41 |
+
- No existing source files were edited.
|
| 42 |
+
|
| 43 |
+
### Likely impact areas
|
| 44 |
+
Given a Python library context and “basic functionality” scope, new files commonly fall into:
|
| 45 |
+
- new module/package entries,
|
| 46 |
+
- helper utilities,
|
| 47 |
+
- tests or fixtures,
|
| 48 |
+
- docs/config metadata.
|
| 49 |
+
|
| 50 |
+
### Risk profile
|
| 51 |
+
- **Runtime risk:** Low to medium (depends on whether new files are imported by default).
|
| 52 |
+
- **Compatibility risk:** Medium (if packaging or import paths are affected).
|
| 53 |
+
- **Quality gate risk:** High due to test failure.
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## 4) Technical Analysis
|
| 58 |
+
|
| 59 |
+
## CI/Workflow
|
| 60 |
+
- Workflow passed, indicating:
|
| 61 |
+
- syntax/lint/build stages likely successful,
|
| 62 |
+
- pipeline orchestration healthy.
|
| 63 |
+
|
| 64 |
+
## Testing
|
| 65 |
+
- Test suite failed despite workflow success.
|
| 66 |
+
- Typical causes in additive-only updates:
|
| 67 |
+
1. New tests introduced but failing assertions.
|
| 68 |
+
2. Environment/dependency mismatch (e.g., optional deps not installed in test matrix).
|
| 69 |
+
3. Discovery/import issues from new package structure.
|
| 70 |
+
4. Version pin conflicts or platform-specific flaky behavior.
|
| 71 |
+
|
| 72 |
+
## Packaging/Import Considerations
|
| 73 |
+
For Python libraries, adding files can still impact:
|
| 74 |
+
- package discovery (`setuptools.find_packages`, `pyproject.toml`, MANIFEST rules),
|
| 75 |
+
- namespace/package `__init__.py` behavior,
|
| 76 |
+
- relative imports and module resolution in tests.
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## 5) Recommendations & Improvements
|
| 81 |
+
|
| 82 |
+
## Immediate (Blocker Resolution)
|
| 83 |
+
1. **Collect failing test logs** and classify failures:
|
| 84 |
+
- assertion failure vs import error vs environment error.
|
| 85 |
+
2. **Reproduce locally** with same Python/test matrix as CI.
|
| 86 |
+
3. **Validate package inclusion**:
|
| 87 |
+
- ensure new modules are included in build/wheel/sdist.
|
| 88 |
+
4. **Check dependency constraints**:
|
| 89 |
+
- lock/relax pins as needed for test environment.
|
| 90 |
+
5. **Rerun targeted tests**, then full suite.
|
| 91 |
+
|
| 92 |
+
## Quality Enhancements
|
| 93 |
+
- Add/verify:
|
| 94 |
+
- smoke tests for newly added functionality,
|
| 95 |
+
- import tests for new modules,
|
| 96 |
+
- minimal integration tests for exposed APIs.
|
| 97 |
+
- If failures are flaky:
|
| 98 |
+
- isolate nondeterministic tests,
|
| 99 |
+
- seed randomness and stabilize fixtures.
|
| 100 |
+
|
| 101 |
+
## Process Improvements
|
| 102 |
+
- Require a **“tests pass” gate** before merge/release.
|
| 103 |
+
- Add PR template fields:
|
| 104 |
+
- “new files added,”
|
| 105 |
+
- “packaging impact,”
|
| 106 |
+
- “test matrix validated.”
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
## 6) Deployment Information
|
| 111 |
+
|
| 112 |
+
## Current readiness
|
| 113 |
+
- **Not deployment-ready** due to failed tests.
|
| 114 |
+
|
| 115 |
+
## Suggested release posture
|
| 116 |
+
- **Hold release** until:
|
| 117 |
+
- all tests pass in primary CI matrix,
|
| 118 |
+
- new files verified in package artifacts,
|
| 119 |
+
- changelog/release notes updated.
|
| 120 |
+
|
| 121 |
+
## Verification checklist before deploy
|
| 122 |
+
- [ ] Full test suite green
|
| 123 |
+
- [ ] Wheel/sdist contain intended new files
|
| 124 |
+
- [ ] Import sanity checks pass (`import deepchem...`)
|
| 125 |
+
- [ ] Basic functionality smoke-tested in clean environment
|
| 126 |
+
- [ ] Versioning/release notes finalized
|
| 127 |
+
|
| 128 |
+
---
|
| 129 |
+
|
| 130 |
+
## 7) Future Planning
|
| 131 |
+
|
| 132 |
+
## Short-term (next iteration)
|
| 133 |
+
- Resolve test failures and backfill missing tests around the added files.
|
| 134 |
+
- Add CI job for packaging validation (`build` + artifact inspection).
|
| 135 |
+
|
| 136 |
+
## Mid-term
|
| 137 |
+
- Expand compatibility matrix (Python versions/platforms) if not already covered.
|
| 138 |
+
- Add lightweight contract tests for public APIs to prevent silent breakage from additive changes.
|
| 139 |
+
|
| 140 |
+
## Long-term
|
| 141 |
+
- Establish change-risk tiers:
|
| 142 |
+
- additive-only, internal refactor, public API impact,
|
| 143 |
+
- each with required test/approval thresholds.
|
| 144 |
+
- Improve observability in CI with clearer failure categorization dashboards.
|
| 145 |
+
|
| 146 |
+
---
|
| 147 |
+
|
| 148 |
+
## 8) Executive Conclusion
|
| 149 |
+
|
| 150 |
+
This change set is **structurally low-risk** (8 new files, no modifications), but the **failed test status is a hard blocker**. Prioritize diagnosing and fixing test failures, verify packaging/import behavior for the new files, and rerun the complete CI matrix before deployment. Once tests are green, this update should be safe to release under a standard minor/internal update process.
|
deepchem/mcp_output/mcp_plugin/__init__.py
ADDED
|
File without changes
|
deepchem/mcp_output/mcp_plugin/adapter.py
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import importlib
|
| 4 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 5 |
+
|
| 6 |
+
source_path = os.path.join(
|
| 7 |
+
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
| 8 |
+
"source",
|
| 9 |
+
)
|
| 10 |
+
sys.path.insert(0, source_path)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class Adapter:
|
| 14 |
+
"""
|
| 15 |
+
Import-mode adapter for selected DeepChem repository modules.
|
| 16 |
+
|
| 17 |
+
This adapter attempts to import and call concrete implementations discovered
|
| 18 |
+
in repository analysis. It exposes:
|
| 19 |
+
- Function wrappers for identified callable functions.
|
| 20 |
+
- Class instance constructors for identified classes.
|
| 21 |
+
- CLI fallback helpers when import path execution is not available.
|
| 22 |
+
|
| 23 |
+
All methods return a unified dictionary with at least:
|
| 24 |
+
{
|
| 25 |
+
"status": "success" | "error" | "fallback",
|
| 26 |
+
...
|
| 27 |
+
}
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
def __init__(self) -> None:
|
| 31 |
+
self.mode = "import"
|
| 32 |
+
self._modules: Dict[str, Any] = {}
|
| 33 |
+
self._class_instances: Dict[str, Any] = {}
|
| 34 |
+
self._import_errors: Dict[str, str] = {}
|
| 35 |
+
self._load_modules()
|
| 36 |
+
|
| 37 |
+
# -------------------------------------------------------------------------
|
| 38 |
+
# Internal utilities
|
| 39 |
+
# -------------------------------------------------------------------------
|
| 40 |
+
def _result(self, status: str, **kwargs: Any) -> Dict[str, Any]:
|
| 41 |
+
payload = {"status": status}
|
| 42 |
+
payload.update(kwargs)
|
| 43 |
+
return payload
|
| 44 |
+
|
| 45 |
+
def _import_module(self, module_path: str) -> Optional[Any]:
|
| 46 |
+
try:
|
| 47 |
+
module = importlib.import_module(module_path)
|
| 48 |
+
self._modules[module_path] = module
|
| 49 |
+
return module
|
| 50 |
+
except Exception as exc:
|
| 51 |
+
self._import_errors[module_path] = (
|
| 52 |
+
f"Failed to import '{module_path}'. "
|
| 53 |
+
f"Verify dependencies and source path. Details: {exc}"
|
| 54 |
+
)
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
def _load_modules(self) -> None:
|
| 58 |
+
module_paths = [
|
| 59 |
+
"datasets.construct_pdbbind_df",
|
| 60 |
+
"docs.source.conf",
|
| 61 |
+
"contrib.visualization.utils",
|
| 62 |
+
"contrib.DeepMHC.bd13_datasets",
|
| 63 |
+
"contrib.DeepMHC.deepmhc",
|
| 64 |
+
"contrib.dragonn.models",
|
| 65 |
+
]
|
| 66 |
+
for mp in module_paths:
|
| 67 |
+
self._import_module(mp)
|
| 68 |
+
|
| 69 |
+
def health_check(self) -> Dict[str, Any]:
|
| 70 |
+
"""
|
| 71 |
+
Report adapter readiness and import status.
|
| 72 |
+
|
| 73 |
+
Returns:
|
| 74 |
+
Dict with loaded modules and import errors.
|
| 75 |
+
"""
|
| 76 |
+
return self._result(
|
| 77 |
+
"success",
|
| 78 |
+
mode=self.mode,
|
| 79 |
+
loaded_modules=sorted(self._modules.keys()),
|
| 80 |
+
import_errors=self._import_errors,
|
| 81 |
+
guidance=(
|
| 82 |
+
"Install optional scientific dependencies (e.g., rdkit, tensorflow, torch) "
|
| 83 |
+
"if specific modules fail to import."
|
| 84 |
+
),
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
def _call_function(
|
| 88 |
+
self,
|
| 89 |
+
module_path: str,
|
| 90 |
+
function_name: str,
|
| 91 |
+
*args: Any,
|
| 92 |
+
**kwargs: Any,
|
| 93 |
+
) -> Dict[str, Any]:
|
| 94 |
+
module = self._modules.get(module_path)
|
| 95 |
+
if module is None:
|
| 96 |
+
msg = self._import_errors.get(
|
| 97 |
+
module_path,
|
| 98 |
+
f"Module '{module_path}' is not available.",
|
| 99 |
+
)
|
| 100 |
+
return self._result(
|
| 101 |
+
"fallback",
|
| 102 |
+
error=msg,
|
| 103 |
+
guidance=(
|
| 104 |
+
f"Cannot call '{function_name}' because import failed. "
|
| 105 |
+
"Check Python path and install missing dependencies."
|
| 106 |
+
),
|
| 107 |
+
)
|
| 108 |
+
fn = getattr(module, function_name, None)
|
| 109 |
+
if fn is None:
|
| 110 |
+
return self._result(
|
| 111 |
+
"error",
|
| 112 |
+
error=f"Function '{function_name}' not found in module '{module_path}'.",
|
| 113 |
+
guidance="Verify repository version and function name.",
|
| 114 |
+
)
|
| 115 |
+
try:
|
| 116 |
+
data = fn(*args, **kwargs)
|
| 117 |
+
return self._result(
|
| 118 |
+
"success",
|
| 119 |
+
module=module_path,
|
| 120 |
+
function=function_name,
|
| 121 |
+
data=data,
|
| 122 |
+
)
|
| 123 |
+
except Exception as exc:
|
| 124 |
+
return self._result(
|
| 125 |
+
"error",
|
| 126 |
+
error=f"Function call failed: {exc}",
|
| 127 |
+
guidance="Validate function parameters and input data format.",
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
def _create_instance(
|
| 131 |
+
self,
|
| 132 |
+
module_path: str,
|
| 133 |
+
class_name: str,
|
| 134 |
+
instance_key: Optional[str] = None,
|
| 135 |
+
*args: Any,
|
| 136 |
+
**kwargs: Any,
|
| 137 |
+
) -> Dict[str, Any]:
|
| 138 |
+
module = self._modules.get(module_path)
|
| 139 |
+
if module is None:
|
| 140 |
+
msg = self._import_errors.get(
|
| 141 |
+
module_path,
|
| 142 |
+
f"Module '{module_path}' is not available.",
|
| 143 |
+
)
|
| 144 |
+
return self._result(
|
| 145 |
+
"fallback",
|
| 146 |
+
error=msg,
|
| 147 |
+
guidance=(
|
| 148 |
+
f"Cannot instantiate '{class_name}' because import failed. "
|
| 149 |
+
"Check dependency installation."
|
| 150 |
+
),
|
| 151 |
+
)
|
| 152 |
+
cls = getattr(module, class_name, None)
|
| 153 |
+
if cls is None:
|
| 154 |
+
return self._result(
|
| 155 |
+
"error",
|
| 156 |
+
error=f"Class '{class_name}' not found in module '{module_path}'.",
|
| 157 |
+
guidance="Verify repository version and class name.",
|
| 158 |
+
)
|
| 159 |
+
try:
|
| 160 |
+
instance = cls(*args, **kwargs)
|
| 161 |
+
key = instance_key or f"{module_path}.{class_name}"
|
| 162 |
+
self._class_instances[key] = instance
|
| 163 |
+
return self._result(
|
| 164 |
+
"success",
|
| 165 |
+
module=module_path,
|
| 166 |
+
class_name=class_name,
|
| 167 |
+
instance_key=key,
|
| 168 |
+
)
|
| 169 |
+
except Exception as exc:
|
| 170 |
+
return self._result(
|
| 171 |
+
"error",
|
| 172 |
+
error=f"Class instantiation failed: {exc}",
|
| 173 |
+
guidance="Check constructor arguments and required runtime dependencies.",
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
# -------------------------------------------------------------------------
|
| 177 |
+
# Functions: datasets.construct_pdbbind_df
|
| 178 |
+
# -------------------------------------------------------------------------
|
| 179 |
+
def call_construct_df(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 180 |
+
"""
|
| 181 |
+
Call datasets.construct_pdbbind_df.construct_df.
|
| 182 |
+
|
| 183 |
+
Parameters:
|
| 184 |
+
*args: Positional arguments forwarded to construct_df.
|
| 185 |
+
**kwargs: Keyword arguments forwarded to construct_df.
|
| 186 |
+
|
| 187 |
+
Returns:
|
| 188 |
+
Unified status dictionary with function output in 'data' on success.
|
| 189 |
+
"""
|
| 190 |
+
return self._call_function("datasets.construct_pdbbind_df", "construct_df", *args, **kwargs)
|
| 191 |
+
|
| 192 |
+
def call_extract_labels(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 193 |
+
"""
|
| 194 |
+
Call datasets.construct_pdbbind_df.extract_labels.
|
| 195 |
+
|
| 196 |
+
Parameters:
|
| 197 |
+
*args: Positional arguments forwarded to extract_labels.
|
| 198 |
+
**kwargs: Keyword arguments forwarded to extract_labels.
|
| 199 |
+
|
| 200 |
+
Returns:
|
| 201 |
+
Unified status dictionary with function output in 'data' on success.
|
| 202 |
+
"""
|
| 203 |
+
return self._call_function("datasets.construct_pdbbind_df", "extract_labels", *args, **kwargs)
|
| 204 |
+
|
| 205 |
+
# -------------------------------------------------------------------------
|
| 206 |
+
# Functions: docs.source.conf
|
| 207 |
+
# -------------------------------------------------------------------------
|
| 208 |
+
def call_linkcode_resolve(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 209 |
+
"""
|
| 210 |
+
Call docs.source.conf.linkcode_resolve.
|
| 211 |
+
|
| 212 |
+
Parameters:
|
| 213 |
+
*args: Positional arguments forwarded to linkcode_resolve.
|
| 214 |
+
**kwargs: Keyword arguments forwarded to linkcode_resolve.
|
| 215 |
+
|
| 216 |
+
Returns:
|
| 217 |
+
Unified status dictionary with resolved link info in 'data' on success.
|
| 218 |
+
"""
|
| 219 |
+
return self._call_function("docs.source.conf", "linkcode_resolve", *args, **kwargs)
|
| 220 |
+
|
| 221 |
+
# -------------------------------------------------------------------------
|
| 222 |
+
# Functions: contrib.visualization.utils
|
| 223 |
+
# -------------------------------------------------------------------------
|
| 224 |
+
def call_combine_mdtraj(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 225 |
+
"""
|
| 226 |
+
Call contrib.visualization.utils.combine_mdtraj.
|
| 227 |
+
|
| 228 |
+
Parameters:
|
| 229 |
+
*args: Positional arguments forwarded to combine_mdtraj.
|
| 230 |
+
**kwargs: Keyword arguments forwarded to combine_mdtraj.
|
| 231 |
+
|
| 232 |
+
Returns:
|
| 233 |
+
Unified status dictionary containing result in 'data' on success.
|
| 234 |
+
"""
|
| 235 |
+
return self._call_function("contrib.visualization.utils", "combine_mdtraj", *args, **kwargs)
|
| 236 |
+
|
| 237 |
+
def call_convert_lines_to_mdtraj(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 238 |
+
"""
|
| 239 |
+
Call contrib.visualization.utils.convert_lines_to_mdtraj.
|
| 240 |
+
|
| 241 |
+
Parameters:
|
| 242 |
+
*args: Positional arguments forwarded to convert_lines_to_mdtraj.
|
| 243 |
+
**kwargs: Keyword arguments forwarded to convert_lines_to_mdtraj.
|
| 244 |
+
|
| 245 |
+
Returns:
|
| 246 |
+
Unified status dictionary containing result in 'data' on success.
|
| 247 |
+
"""
|
| 248 |
+
return self._call_function("contrib.visualization.utils", "convert_lines_to_mdtraj", *args, **kwargs)
|
| 249 |
+
|
| 250 |
+
def call_display_images(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 251 |
+
"""
|
| 252 |
+
Call contrib.visualization.utils.display_images.
|
| 253 |
+
|
| 254 |
+
Parameters:
|
| 255 |
+
*args: Positional arguments forwarded to display_images.
|
| 256 |
+
**kwargs: Keyword arguments forwarded to display_images.
|
| 257 |
+
|
| 258 |
+
Returns:
|
| 259 |
+
Unified status dictionary containing result in 'data' on success.
|
| 260 |
+
"""
|
| 261 |
+
return self._call_function("contrib.visualization.utils", "display_images", *args, **kwargs)
|
| 262 |
+
|
| 263 |
+
# -------------------------------------------------------------------------
|
| 264 |
+
# Functions: contrib.DeepMHC.bd13_datasets
|
| 265 |
+
# -------------------------------------------------------------------------
|
| 266 |
+
def call_featurize(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 267 |
+
"""
|
| 268 |
+
Call contrib.DeepMHC.bd13_datasets.featurize.
|
| 269 |
+
|
| 270 |
+
Parameters:
|
| 271 |
+
*args: Positional arguments forwarded to featurize.
|
| 272 |
+
**kwargs: Keyword arguments forwarded to featurize.
|
| 273 |
+
|
| 274 |
+
Returns:
|
| 275 |
+
Unified status dictionary containing featurized output in 'data' on success.
|
| 276 |
+
"""
|
| 277 |
+
return self._call_function("contrib.DeepMHC.bd13_datasets", "featurize", *args, **kwargs)
|
| 278 |
+
|
| 279 |
+
def call_load_bd2013_human(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 280 |
+
"""
|
| 281 |
+
Call contrib.DeepMHC.bd13_datasets.load_bd2013_human.
|
| 282 |
+
|
| 283 |
+
Parameters:
|
| 284 |
+
*args: Positional arguments forwarded to load_bd2013_human.
|
| 285 |
+
**kwargs: Keyword arguments forwarded to load_bd2013_human.
|
| 286 |
+
|
| 287 |
+
Returns:
|
| 288 |
+
Unified status dictionary with loaded dataset artifacts in 'data' on success.
|
| 289 |
+
"""
|
| 290 |
+
return self._call_function("contrib.DeepMHC.bd13_datasets", "load_bd2013_human", *args, **kwargs)
|
| 291 |
+
|
| 292 |
+
def call_to_one_hot_array(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
| 293 |
+
"""
|
| 294 |
+
Call contrib.DeepMHC.bd13_datasets.to_one_hot_array.
|
| 295 |
+
|
| 296 |
+
Parameters:
|
| 297 |
+
*args: Positional arguments forwarded to to_one_hot_array.
|
| 298 |
+
**kwargs: Keyword arguments forwarded to to_one_hot_array.
|
| 299 |
+
|
| 300 |
+
Returns:
|
| 301 |
+
Unified status dictionary with encoded array in 'data' on success.
|
| 302 |
+
"""
|
| 303 |
+
return self._call_function("contrib.DeepMHC.bd13_datasets", "to_one_hot_array", *args, **kwargs)
|
| 304 |
+
|
| 305 |
+
# -------------------------------------------------------------------------
|
| 306 |
+
# Classes: contrib.DeepMHC.deepmhc.DeepMHC
|
| 307 |
+
# -------------------------------------------------------------------------
|
| 308 |
+
def create_deepmhc(self, *args: Any, instance_key: Optional[str] = None, **kwargs: Any) -> Dict[str, Any]:
|
| 309 |
+
"""
|
| 310 |
+
Instantiate contrib.DeepMHC.deepmhc.DeepMHC.
|
| 311 |
+
|
| 312 |
+
Parameters:
|
| 313 |
+
*args: Positional constructor args.
|
| 314 |
+
instance_key: Optional storage key for later retrieval.
|
| 315 |
+
**kwargs: Keyword constructor args.
|
| 316 |
+
|
| 317 |
+
Returns:
|
| 318 |
+
Unified status dictionary with 'instance_key' on success.
|
| 319 |
+
"""
|
| 320 |
+
return self._create_instance(
|
| 321 |
+
"contrib.DeepMHC.deepmhc",
|
| 322 |
+
"DeepMHC",
|
| 323 |
+
instance_key,
|
| 324 |
+
*args,
|
| 325 |
+
**kwargs,
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
# -------------------------------------------------------------------------
|
| 329 |
+
# Classes: contrib.dragonn.models
|
| 330 |
+
# -------------------------------------------------------------------------
|
| 331 |
+
def create_motif_score_rnn(self, *args: Any, instance_key: Optional[str] = None, **kwargs: Any) -> Dict[str, Any]:
|
| 332 |
+
"""
|
| 333 |
+
Instantiate contrib.dragonn.models.MotifScoreRNN.
|
| 334 |
+
|
| 335 |
+
Parameters:
|
| 336 |
+
*args: Positional constructor args.
|
| 337 |
+
instance_key: Optional storage key for later retrieval.
|
| 338 |
+
**kwargs: Keyword constructor args.
|
| 339 |
+
|
| 340 |
+
Returns:
|
| 341 |
+
Unified status dictionary with 'instance_key' on success.
|
| 342 |
+
"""
|
| 343 |
+
return self._create_instance(
|
| 344 |
+
"contrib.dragonn.models",
|
| 345 |
+
"MotifScoreRNN",
|
| 346 |
+
instance_key,
|
| 347 |
+
*args,
|
| 348 |
+
**kwargs,
|
| 349 |
+
)
|
| 350 |
+
|
| 351 |
+
def create_gkmsvm(self, *args: Any, instance_key: Optional[str] = None, **kwargs: Any) -> Dict[str, Any]:
|
| 352 |
+
"""
|
| 353 |
+
Instantiate contrib.dragonn.models.gkmSVM.
|
| 354 |
+
|
| 355 |
+
Parameters:
|
| 356 |
+
*args: Positional constructor args.
|
| 357 |
+
instance_key: Optional storage key for later retrieval.
|
| 358 |
+
**kwargs: Keyword constructor args.
|
| 359 |
+
|
| 360 |
+
Returns:
|
| 361 |
+
Unified status dictionary with 'instance_key' on success.
|
| 362 |
+
"""
|
| 363 |
+
return self._create_instance(
|
| 364 |
+
"contrib.dragonn.models",
|
| 365 |
+
"gkmSVM",
|
| 366 |
+
instance_key,
|
| 367 |
+
*args,
|
| 368 |
+
**kwargs,
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
+
# -------------------------------------------------------------------------
|
| 372 |
+
# Instance management
|
| 373 |
+
# -------------------------------------------------------------------------
|
| 374 |
+
def list_instances(self) -> Dict[str, Any]:
|
| 375 |
+
"""
|
| 376 |
+
List cached class instances created by this adapter.
|
| 377 |
+
|
| 378 |
+
Returns:
|
| 379 |
+
Unified status dictionary containing instance keys.
|
| 380 |
+
"""
|
| 381 |
+
return self._result("success", instances=sorted(self._class_instances.keys()))
|
| 382 |
+
|
| 383 |
+
def call_instance_method(
|
| 384 |
+
self,
|
| 385 |
+
instance_key: str,
|
| 386 |
+
method_name: str,
|
| 387 |
+
*args: Any,
|
| 388 |
+
**kwargs: Any,
|
| 389 |
+
) -> Dict[str, Any]:
|
| 390 |
+
"""
|
| 391 |
+
Invoke a method on a previously created instance.
|
| 392 |
+
|
| 393 |
+
Parameters:
|
| 394 |
+
instance_key: Key returned by create_* method.
|
| 395 |
+
method_name: Target method name on the instance.
|
| 396 |
+
*args: Positional arguments for the instance method.
|
| 397 |
+
**kwargs: Keyword arguments for the instance method.
|
| 398 |
+
|
| 399 |
+
Returns:
|
| 400 |
+
Unified status dictionary with method result in 'data' on success.
|
| 401 |
+
"""
|
| 402 |
+
inst = self._class_instances.get(instance_key)
|
| 403 |
+
if inst is None:
|
| 404 |
+
return self._result(
|
| 405 |
+
"error",
|
| 406 |
+
error=f"Instance '{instance_key}' not found.",
|
| 407 |
+
guidance="Create the instance first using the matching create_* method.",
|
| 408 |
+
)
|
| 409 |
+
method = getattr(inst, method_name, None)
|
| 410 |
+
if method is None or not callable(method):
|
| 411 |
+
return self._result(
|
| 412 |
+
"error",
|
| 413 |
+
error=f"Method '{method_name}' not found on instance '{instance_key}'.",
|
| 414 |
+
guidance="Check available methods with dir(instance).",
|
| 415 |
+
)
|
| 416 |
+
try:
|
| 417 |
+
data = method(*args, **kwargs)
|
| 418 |
+
return self._result("success", instance_key=instance_key, method=method_name, data=data)
|
| 419 |
+
except Exception as exc:
|
| 420 |
+
return self._result(
|
| 421 |
+
"error",
|
| 422 |
+
error=f"Instance method call failed: {exc}",
|
| 423 |
+
guidance="Validate method parameters and ensure model state is initialized.",
|
| 424 |
+
)
|
| 425 |
+
|
| 426 |
+
# -------------------------------------------------------------------------
|
| 427 |
+
# CLI fallback helpers
|
| 428 |
+
# -------------------------------------------------------------------------
|
| 429 |
+
def cli_run_benchmark(self, extra_args: Optional[List[str]] = None) -> Dict[str, Any]:
|
| 430 |
+
"""
|
| 431 |
+
Provide CLI fallback guidance for MolNet benchmark execution.
|
| 432 |
+
|
| 433 |
+
Parameters:
|
| 434 |
+
extra_args: Optional CLI args to append.
|
| 435 |
+
|
| 436 |
+
Returns:
|
| 437 |
+
Unified status dictionary with a suggested command.
|
| 438 |
+
"""
|
| 439 |
+
cmd = ["python", "-m", "source.deepchem.molnet.run_benchmark"] + (extra_args or [])
|
| 440 |
+
return self._result(
|
| 441 |
+
"fallback",
|
| 442 |
+
command=cmd,
|
| 443 |
+
guidance=(
|
| 444 |
+
"Use this command in a shell when import-mode execution is unavailable. "
|
| 445 |
+
"Ensure dependencies are installed and run from project root."
|
| 446 |
+
),
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
def cli_run_benchmark_low_data(self, extra_args: Optional[List[str]] = None) -> Dict[str, Any]:
|
| 450 |
+
"""
|
| 451 |
+
Provide CLI fallback guidance for low-data benchmark workflow.
|
| 452 |
+
|
| 453 |
+
Parameters:
|
| 454 |
+
extra_args: Optional CLI args to append.
|
| 455 |
+
|
| 456 |
+
Returns:
|
| 457 |
+
Unified status dictionary with a suggested command.
|
| 458 |
+
"""
|
| 459 |
+
cmd = ["python", "-m", "source.deepchem.molnet.run_benchmark_low_data"] + (extra_args or [])
|
| 460 |
+
return self._result(
|
| 461 |
+
"fallback",
|
| 462 |
+
command=cmd,
|
| 463 |
+
guidance="Run in shell as fallback. Verify low-data benchmark options before execution.",
|
| 464 |
+
)
|
| 465 |
+
|
| 466 |
+
def cli_run_example_benchmark(self, extra_args: Optional[List[str]] = None) -> Dict[str, Any]:
|
| 467 |
+
"""
|
| 468 |
+
Provide CLI fallback guidance for example benchmark runner.
|
| 469 |
+
|
| 470 |
+
Parameters:
|
| 471 |
+
extra_args: Optional CLI args to append.
|
| 472 |
+
|
| 473 |
+
Returns:
|
| 474 |
+
Unified status dictionary with a suggested command.
|
| 475 |
+
"""
|
| 476 |
+
cmd = ["python", "-m", "source.examples.benchmark"] + (extra_args or [])
|
| 477 |
+
return self._result(
|
| 478 |
+
"fallback",
|
| 479 |
+
command=cmd,
|
| 480 |
+
guidance="This is a demo-oriented runner and may be less stable than core benchmark scripts.",
|
| 481 |
+
)
|
deepchem/mcp_output/mcp_plugin/main.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MCP Service Auto-Wrapper - Auto-generated
|
| 3 |
+
"""
|
| 4 |
+
from mcp_service import create_app
|
| 5 |
+
|
| 6 |
+
def main():
|
| 7 |
+
"""Main entry point"""
|
| 8 |
+
app = create_app()
|
| 9 |
+
return app
|
| 10 |
+
|
| 11 |
+
if __name__ == "__main__":
|
| 12 |
+
app = main()
|
| 13 |
+
app.run()
|
deepchem/mcp_output/mcp_plugin/mcp_service.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
source_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "source")
|
| 5 |
+
if source_path not in sys.path:
|
| 6 |
+
sys.path.insert(0, source_path)
|
| 7 |
+
|
| 8 |
+
from fastmcp import FastMCP
|
| 9 |
+
|
| 10 |
+
from datasets.construct_pdbbind_df import construct_df, extract_labels
|
| 11 |
+
from docs.source.conf import linkcode_resolve
|
| 12 |
+
from contrib.visualization.utils import combine_mdtraj, display_images, convert_lines_to_mdtraj
|
| 13 |
+
from contrib.DeepMHC.bd13_datasets import load_bd2013_human, to_one_hot_array, featurize
|
| 14 |
+
from contrib.DeepMHC.deepmhc import DeepMHC
|
| 15 |
+
from contrib.dragonn.models import MotifScoreRNN, gkmSVM
|
| 16 |
+
|
| 17 |
+
mcp = FastMCP("unknown_service")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@mcp.tool(name="construct_df", description="Auto-wrapped function construct_df")
|
| 21 |
+
def construct_df(payload: dict):
|
| 22 |
+
try:
|
| 23 |
+
if construct_df is None:
|
| 24 |
+
return {"success": False, "result": None, "error": "Function construct_df is not available"}
|
| 25 |
+
result = construct_df(**payload)
|
| 26 |
+
return {"success": True, "result": result, "error": None}
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 29 |
+
|
| 30 |
+
@mcp.tool(name="extract_labels", description="Auto-wrapped function extract_labels")
|
| 31 |
+
def extract_labels(payload: dict):
|
| 32 |
+
try:
|
| 33 |
+
if extract_labels is None:
|
| 34 |
+
return {"success": False, "result": None, "error": "Function extract_labels is not available"}
|
| 35 |
+
result = extract_labels(**payload)
|
| 36 |
+
return {"success": True, "result": result, "error": None}
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 39 |
+
|
| 40 |
+
@mcp.tool(name="linkcode_resolve", description="Auto-wrapped function linkcode_resolve")
|
| 41 |
+
def linkcode_resolve(payload: dict):
|
| 42 |
+
try:
|
| 43 |
+
if linkcode_resolve is None:
|
| 44 |
+
return {"success": False, "result": None, "error": "Function linkcode_resolve is not available"}
|
| 45 |
+
result = linkcode_resolve(**payload)
|
| 46 |
+
return {"success": True, "result": result, "error": None}
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 49 |
+
|
| 50 |
+
@mcp.tool(name="combine_mdtraj", description="Auto-wrapped function combine_mdtraj")
|
| 51 |
+
def combine_mdtraj(payload: dict):
|
| 52 |
+
try:
|
| 53 |
+
if combine_mdtraj is None:
|
| 54 |
+
return {"success": False, "result": None, "error": "Function combine_mdtraj is not available"}
|
| 55 |
+
result = combine_mdtraj(**payload)
|
| 56 |
+
return {"success": True, "result": result, "error": None}
|
| 57 |
+
except Exception as e:
|
| 58 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 59 |
+
|
| 60 |
+
@mcp.tool(name="convert_lines_to_mdtraj", description="Auto-wrapped function convert_lines_to_mdtraj")
|
| 61 |
+
def convert_lines_to_mdtraj(payload: dict):
|
| 62 |
+
try:
|
| 63 |
+
if convert_lines_to_mdtraj is None:
|
| 64 |
+
return {"success": False, "result": None, "error": "Function convert_lines_to_mdtraj is not available"}
|
| 65 |
+
result = convert_lines_to_mdtraj(**payload)
|
| 66 |
+
return {"success": True, "result": result, "error": None}
|
| 67 |
+
except Exception as e:
|
| 68 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 69 |
+
|
| 70 |
+
@mcp.tool(name="display_images", description="Auto-wrapped function display_images")
|
| 71 |
+
def display_images(payload: dict):
|
| 72 |
+
try:
|
| 73 |
+
if display_images is None:
|
| 74 |
+
return {"success": False, "result": None, "error": "Function display_images is not available"}
|
| 75 |
+
result = display_images(**payload)
|
| 76 |
+
return {"success": True, "result": result, "error": None}
|
| 77 |
+
except Exception as e:
|
| 78 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 79 |
+
|
| 80 |
+
@mcp.tool(name="featurize", description="Auto-wrapped function featurize")
|
| 81 |
+
def featurize(payload: dict):
|
| 82 |
+
try:
|
| 83 |
+
if featurize is None:
|
| 84 |
+
return {"success": False, "result": None, "error": "Function featurize is not available"}
|
| 85 |
+
result = featurize(**payload)
|
| 86 |
+
return {"success": True, "result": result, "error": None}
|
| 87 |
+
except Exception as e:
|
| 88 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 89 |
+
|
| 90 |
+
@mcp.tool(name="load_bd2013_human", description="Auto-wrapped function load_bd2013_human")
|
| 91 |
+
def load_bd2013_human(payload: dict):
|
| 92 |
+
try:
|
| 93 |
+
if load_bd2013_human is None:
|
| 94 |
+
return {"success": False, "result": None, "error": "Function load_bd2013_human is not available"}
|
| 95 |
+
result = load_bd2013_human(**payload)
|
| 96 |
+
return {"success": True, "result": result, "error": None}
|
| 97 |
+
except Exception as e:
|
| 98 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 99 |
+
|
| 100 |
+
@mcp.tool(name="to_one_hot_array", description="Auto-wrapped function to_one_hot_array")
|
| 101 |
+
def to_one_hot_array(payload: dict):
|
| 102 |
+
try:
|
| 103 |
+
if to_one_hot_array is None:
|
| 104 |
+
return {"success": False, "result": None, "error": "Function to_one_hot_array is not available"}
|
| 105 |
+
result = to_one_hot_array(**payload)
|
| 106 |
+
return {"success": True, "result": result, "error": None}
|
| 107 |
+
except Exception as e:
|
| 108 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 109 |
+
|
| 110 |
+
@mcp.tool(name="deepmhc", description="DeepMHC class")
|
| 111 |
+
def deepmhc(*args, **kwargs):
|
| 112 |
+
"""DeepMHC class"""
|
| 113 |
+
try:
|
| 114 |
+
if DeepMHC is None:
|
| 115 |
+
return {"success": False, "result": None, "error": "Class DeepMHC is not available, path may need adjustment"}
|
| 116 |
+
|
| 117 |
+
# MCP parameter type conversion
|
| 118 |
+
converted_args = []
|
| 119 |
+
converted_kwargs = kwargs.copy()
|
| 120 |
+
|
| 121 |
+
# Handle position argument type conversion
|
| 122 |
+
for arg in args:
|
| 123 |
+
if isinstance(arg, str):
|
| 124 |
+
# Try to convert to numeric type
|
| 125 |
+
try:
|
| 126 |
+
if '.' in arg:
|
| 127 |
+
converted_args.append(float(arg))
|
| 128 |
+
else:
|
| 129 |
+
converted_args.append(int(arg))
|
| 130 |
+
except ValueError:
|
| 131 |
+
converted_args.append(arg)
|
| 132 |
+
else:
|
| 133 |
+
converted_args.append(arg)
|
| 134 |
+
|
| 135 |
+
# Handle keyword argument type conversion
|
| 136 |
+
for key, value in converted_kwargs.items():
|
| 137 |
+
if isinstance(value, str):
|
| 138 |
+
try:
|
| 139 |
+
if '.' in value:
|
| 140 |
+
converted_kwargs[key] = float(value)
|
| 141 |
+
else:
|
| 142 |
+
converted_kwargs[key] = int(value)
|
| 143 |
+
except ValueError:
|
| 144 |
+
pass
|
| 145 |
+
|
| 146 |
+
instance = DeepMHC(*converted_args, **converted_kwargs)
|
| 147 |
+
return {"success": True, "result": str(instance), "error": None}
|
| 148 |
+
except Exception as e:
|
| 149 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 150 |
+
|
| 151 |
+
@mcp.tool(name="motifscorernn", description="MotifScoreRNN class")
|
| 152 |
+
def motifscorernn(*args, **kwargs):
|
| 153 |
+
"""MotifScoreRNN class"""
|
| 154 |
+
try:
|
| 155 |
+
if MotifScoreRNN is None:
|
| 156 |
+
return {"success": False, "result": None, "error": "Class MotifScoreRNN is not available, path may need adjustment"}
|
| 157 |
+
|
| 158 |
+
# MCP parameter type conversion
|
| 159 |
+
converted_args = []
|
| 160 |
+
converted_kwargs = kwargs.copy()
|
| 161 |
+
|
| 162 |
+
# Handle position argument type conversion
|
| 163 |
+
for arg in args:
|
| 164 |
+
if isinstance(arg, str):
|
| 165 |
+
# Try to convert to numeric type
|
| 166 |
+
try:
|
| 167 |
+
if '.' in arg:
|
| 168 |
+
converted_args.append(float(arg))
|
| 169 |
+
else:
|
| 170 |
+
converted_args.append(int(arg))
|
| 171 |
+
except ValueError:
|
| 172 |
+
converted_args.append(arg)
|
| 173 |
+
else:
|
| 174 |
+
converted_args.append(arg)
|
| 175 |
+
|
| 176 |
+
# Handle keyword argument type conversion
|
| 177 |
+
for key, value in converted_kwargs.items():
|
| 178 |
+
if isinstance(value, str):
|
| 179 |
+
try:
|
| 180 |
+
if '.' in value:
|
| 181 |
+
converted_kwargs[key] = float(value)
|
| 182 |
+
else:
|
| 183 |
+
converted_kwargs[key] = int(value)
|
| 184 |
+
except ValueError:
|
| 185 |
+
pass
|
| 186 |
+
|
| 187 |
+
instance = MotifScoreRNN(*converted_args, **converted_kwargs)
|
| 188 |
+
return {"success": True, "result": str(instance), "error": None}
|
| 189 |
+
except Exception as e:
|
| 190 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 191 |
+
|
| 192 |
+
@mcp.tool(name="gkmsvm", description="gkmSVM class")
|
| 193 |
+
def gkmsvm(*args, **kwargs):
|
| 194 |
+
"""gkmSVM class"""
|
| 195 |
+
try:
|
| 196 |
+
if gkmSVM is None:
|
| 197 |
+
return {"success": False, "result": None, "error": "Class gkmSVM is not available, path may need adjustment"}
|
| 198 |
+
|
| 199 |
+
# MCP parameter type conversion
|
| 200 |
+
converted_args = []
|
| 201 |
+
converted_kwargs = kwargs.copy()
|
| 202 |
+
|
| 203 |
+
# Handle position argument type conversion
|
| 204 |
+
for arg in args:
|
| 205 |
+
if isinstance(arg, str):
|
| 206 |
+
# Try to convert to numeric type
|
| 207 |
+
try:
|
| 208 |
+
if '.' in arg:
|
| 209 |
+
converted_args.append(float(arg))
|
| 210 |
+
else:
|
| 211 |
+
converted_args.append(int(arg))
|
| 212 |
+
except ValueError:
|
| 213 |
+
converted_args.append(arg)
|
| 214 |
+
else:
|
| 215 |
+
converted_args.append(arg)
|
| 216 |
+
|
| 217 |
+
# Handle keyword argument type conversion
|
| 218 |
+
for key, value in converted_kwargs.items():
|
| 219 |
+
if isinstance(value, str):
|
| 220 |
+
try:
|
| 221 |
+
if '.' in value:
|
| 222 |
+
converted_kwargs[key] = float(value)
|
| 223 |
+
else:
|
| 224 |
+
converted_kwargs[key] = int(value)
|
| 225 |
+
except ValueError:
|
| 226 |
+
pass
|
| 227 |
+
|
| 228 |
+
instance = gkmSVM(*converted_args, **converted_kwargs)
|
| 229 |
+
return {"success": True, "result": str(instance), "error": None}
|
| 230 |
+
except Exception as e:
|
| 231 |
+
return {"success": False, "result": None, "error": str(e)}
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def create_app():
|
| 236 |
+
"""Create and return FastMCP application instance"""
|
| 237 |
+
return mcp
|
| 238 |
+
|
| 239 |
+
if __name__ == "__main__":
|
| 240 |
+
mcp.run(transport="http", host="0.0.0.0", port=8000)
|
deepchem/mcp_output/requirements.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
fastapi
|
| 3 |
+
uvicorn[standard]
|
| 4 |
+
pydantic>=2.0.0
|
| 5 |
+
joblib
|
| 6 |
+
numpy<2
|
| 7 |
+
pandas
|
| 8 |
+
scikit-learn
|
| 9 |
+
sympy
|
| 10 |
+
scipy>=1.10.1
|
| 11 |
+
rdkit
|
| 12 |
+
numpy
|
| 13 |
+
tqdm
|
deepchem/mcp_output/start_mcp.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
"""
|
| 3 |
+
MCP Service Startup Entry
|
| 4 |
+
"""
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
project_root = os.path.dirname(os.path.abspath(__file__))
|
| 9 |
+
mcp_plugin_dir = os.path.join(project_root, "mcp_plugin")
|
| 10 |
+
if mcp_plugin_dir not in sys.path:
|
| 11 |
+
sys.path.insert(0, mcp_plugin_dir)
|
| 12 |
+
|
| 13 |
+
from mcp_service import create_app
|
| 14 |
+
|
| 15 |
+
def main():
|
| 16 |
+
"""Start FastMCP service"""
|
| 17 |
+
app = create_app()
|
| 18 |
+
# Use environment variable to configure port, default 8000
|
| 19 |
+
port = int(os.environ.get("MCP_PORT", "8000"))
|
| 20 |
+
|
| 21 |
+
# Choose transport mode based on environment variable
|
| 22 |
+
transport = os.environ.get("MCP_TRANSPORT", "stdio")
|
| 23 |
+
if transport == "http":
|
| 24 |
+
app.run(transport="http", host="0.0.0.0", port=port)
|
| 25 |
+
else:
|
| 26 |
+
# Default to STDIO mode
|
| 27 |
+
app.run()
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
main()
|
deepchem/mcp_output/workflow_summary.json
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"repository": {
|
| 3 |
+
"name": "deepchem",
|
| 4 |
+
"url": "https://github.com/deepchem/deepchem",
|
| 5 |
+
"local_path": "/Users/ghh/Documents/Code/Code2MCP-private/workspace/deepchem",
|
| 6 |
+
"description": "Python library",
|
| 7 |
+
"features": "Basic functionality",
|
| 8 |
+
"tech_stack": "Python",
|
| 9 |
+
"stars": 0,
|
| 10 |
+
"forks": 0,
|
| 11 |
+
"language": "Python",
|
| 12 |
+
"last_updated": "",
|
| 13 |
+
"complexity": "complex",
|
| 14 |
+
"intrusiveness_risk": "medium"
|
| 15 |
+
},
|
| 16 |
+
"execution": {
|
| 17 |
+
"start_time": 1773459511.7688398,
|
| 18 |
+
"end_time": 1773459926.1967611,
|
| 19 |
+
"duration": 414.427921295166,
|
| 20 |
+
"status": "success",
|
| 21 |
+
"workflow_status": "success",
|
| 22 |
+
"nodes_executed": [
|
| 23 |
+
"download",
|
| 24 |
+
"analysis",
|
| 25 |
+
"env",
|
| 26 |
+
"generate",
|
| 27 |
+
"run",
|
| 28 |
+
"review",
|
| 29 |
+
"finalize"
|
| 30 |
+
],
|
| 31 |
+
"total_files_processed": 24,
|
| 32 |
+
"environment_type": "unknown",
|
| 33 |
+
"llm_calls": 0,
|
| 34 |
+
"deepwiki_calls": 0
|
| 35 |
+
},
|
| 36 |
+
"tests": {
|
| 37 |
+
"original_project": {
|
| 38 |
+
"passed": false,
|
| 39 |
+
"details": {},
|
| 40 |
+
"test_coverage": "100%",
|
| 41 |
+
"execution_time": 0,
|
| 42 |
+
"test_files": []
|
| 43 |
+
},
|
| 44 |
+
"mcp_plugin": {
|
| 45 |
+
"passed": true,
|
| 46 |
+
"details": {},
|
| 47 |
+
"service_health": "healthy",
|
| 48 |
+
"startup_time": 0,
|
| 49 |
+
"transport_mode": "stdio",
|
| 50 |
+
"fastmcp_version": "unknown",
|
| 51 |
+
"mcp_version": "unknown"
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"analysis": {
|
| 55 |
+
"structure": {
|
| 56 |
+
"packages": [
|
| 57 |
+
"deployment.deepchem.source",
|
| 58 |
+
"mcp_output.mcp_plugin",
|
| 59 |
+
"source.contrib.autoencoder_models",
|
| 60 |
+
"source.contrib.nn",
|
| 61 |
+
"source.contrib.tensorflow_models",
|
| 62 |
+
"source.deepchem",
|
| 63 |
+
"source.deepchem.data",
|
| 64 |
+
"source.deepchem.dock",
|
| 65 |
+
"source.deepchem.feat",
|
| 66 |
+
"source.deepchem.hyper",
|
| 67 |
+
"source.deepchem.metalearning",
|
| 68 |
+
"source.deepchem.metrics",
|
| 69 |
+
"source.deepchem.models",
|
| 70 |
+
"source.deepchem.molnet",
|
| 71 |
+
"source.deepchem.rl",
|
| 72 |
+
"source.deepchem.splits",
|
| 73 |
+
"source.deepchem.trans",
|
| 74 |
+
"source.deepchem.utils",
|
| 75 |
+
"source.examples.adme",
|
| 76 |
+
"source.examples.chembl",
|
| 77 |
+
"source.examples.clintox",
|
| 78 |
+
"source.examples.encoders",
|
| 79 |
+
"source.examples.low_data",
|
| 80 |
+
"source.examples.membrane_permeability"
|
| 81 |
+
]
|
| 82 |
+
},
|
| 83 |
+
"dependencies": {
|
| 84 |
+
"has_environment_yml": false,
|
| 85 |
+
"has_requirements_txt": false,
|
| 86 |
+
"pyproject": false,
|
| 87 |
+
"setup_cfg": true,
|
| 88 |
+
"setup_py": true
|
| 89 |
+
},
|
| 90 |
+
"entry_points": {
|
| 91 |
+
"imports": [],
|
| 92 |
+
"cli": [],
|
| 93 |
+
"modules": []
|
| 94 |
+
},
|
| 95 |
+
"risk_assessment": {
|
| 96 |
+
"import_feasibility": 0.82,
|
| 97 |
+
"intrusiveness_risk": "medium",
|
| 98 |
+
"complexity": "complex"
|
| 99 |
+
},
|
| 100 |
+
"deepwiki_analysis": {
|
| 101 |
+
"repo_url": "https://github.com/deepchem/deepchem",
|
| 102 |
+
"repo_name": "deepchem",
|
| 103 |
+
"error": "DeepWiki analysis failed",
|
| 104 |
+
"model": "gpt-5.3-codex",
|
| 105 |
+
"source": "llm_direct_analysis",
|
| 106 |
+
"success": false
|
| 107 |
+
},
|
| 108 |
+
"code_complexity": {
|
| 109 |
+
"cyclomatic_complexity": "medium",
|
| 110 |
+
"cognitive_complexity": "medium",
|
| 111 |
+
"maintainability_index": 75
|
| 112 |
+
},
|
| 113 |
+
"security_analysis": {
|
| 114 |
+
"vulnerabilities_found": 0,
|
| 115 |
+
"security_score": 85,
|
| 116 |
+
"recommendations": []
|
| 117 |
+
}
|
| 118 |
+
},
|
| 119 |
+
"plugin_generation": {
|
| 120 |
+
"files_created": [
|
| 121 |
+
"mcp_output/start_mcp.py",
|
| 122 |
+
"mcp_output/mcp_plugin/__init__.py",
|
| 123 |
+
"mcp_output/mcp_plugin/mcp_service.py",
|
| 124 |
+
"mcp_output/mcp_plugin/adapter.py",
|
| 125 |
+
"mcp_output/mcp_plugin/main.py",
|
| 126 |
+
"mcp_output/requirements.txt",
|
| 127 |
+
"mcp_output/README_MCP.md"
|
| 128 |
+
],
|
| 129 |
+
"main_entry": "start_mcp.py",
|
| 130 |
+
"requirements": [
|
| 131 |
+
"fastmcp>=0.1.0",
|
| 132 |
+
"pydantic>=2.0.0"
|
| 133 |
+
],
|
| 134 |
+
"readme_path": "/Users/ghh/Documents/Code/Code2MCP-private/workspace/deepchem/mcp_output/README_MCP.md",
|
| 135 |
+
"adapter_mode": "import",
|
| 136 |
+
"total_lines_of_code": 0,
|
| 137 |
+
"generated_files_size": 0,
|
| 138 |
+
"tool_endpoints": 0,
|
| 139 |
+
"supported_features": [
|
| 140 |
+
"Basic functionality"
|
| 141 |
+
],
|
| 142 |
+
"generated_tools": [
|
| 143 |
+
"Basic tools",
|
| 144 |
+
"Health check tools",
|
| 145 |
+
"Version info tools"
|
| 146 |
+
]
|
| 147 |
+
},
|
| 148 |
+
"code_review": {},
|
| 149 |
+
"errors": [],
|
| 150 |
+
"warnings": [],
|
| 151 |
+
"recommendations": [
|
| 152 |
+
"add a minimal but real smoke-test suite (import core packages",
|
| 153 |
+
"run one tiny featurizer/model fit) since test status is empty",
|
| 154 |
+
"reduce MCP surface area by exposing only curated/stable endpoints (current list is excessively broad and risky)",
|
| 155 |
+
"introduce endpoint namespacing/versioning (e.g.",
|
| 156 |
+
"`models.train.v1`) and de-duplicate collisions like repeated `params`/`softmax`",
|
| 157 |
+
"add strict input/output schemas and runtime validation for every MCP endpoint (Pydantic models",
|
| 158 |
+
"bounds",
|
| 159 |
+
"enum constraints)",
|
| 160 |
+
"create a dependency-tier test matrix in CI (base",
|
| 161 |
+
"rdkit",
|
| 162 |
+
"torch",
|
| 163 |
+
"tensorflow",
|
| 164 |
+
"jax",
|
| 165 |
+
"optional extras) with clear required vs optional gating",
|
| 166 |
+
"publish a canonical `pyproject.toml` (while keeping setup.py compatibility if needed) and generate lockfiles for reproducible environments",
|
| 167 |
+
"add contract tests for plugin adapter mode (`import` fallback to `cli`) and failure-mode tests for missing optional deps",
|
| 168 |
+
"mark `contrib/` modules as experimental/legacy in docs and exclude them from default MCP export",
|
| 169 |
+
"prioritize refactoring oversized/high-churn files (`deepchem/models/torch_models/layers.py`",
|
| 170 |
+
"`deepchem/models/layers.py`",
|
| 171 |
+
"dataset utilities) into smaller modules with ownership",
|
| 172 |
+
"enforce type coverage on public APIs and MCP-exposed functions (mypy/pyright in CI)",
|
| 173 |
+
"add performance regression benchmarks for representative workloads (featurization",
|
| 174 |
+
"dataloading",
|
| 175 |
+
"torch training step)",
|
| 176 |
+
"improve observability with structured logs/error codes in MCP service and endpoint-level latency/error metrics",
|
| 177 |
+
"harden security by restricting filesystem/network-capable endpoints and adding allowlists/sandboxing for loader utilities",
|
| 178 |
+
"create a compatibility policy and deprecation workflow for renamed/removed endpoints",
|
| 179 |
+
"add golden integration tests for top CLI entry points (`run_benchmark`",
|
| 180 |
+
"low-data benchmark",
|
| 181 |
+
"example benchmark)",
|
| 182 |
+
"improve docs discoverability with a generated endpoint catalog (stable vs experimental",
|
| 183 |
+
"dependency requirements",
|
| 184 |
+
"examples)",
|
| 185 |
+
"add pre-commit rules for import hygiene/complexity thresholds to prevent further API sprawl",
|
| 186 |
+
"define a release checklist that includes MCP contract diff",
|
| 187 |
+
"dependency drift audit",
|
| 188 |
+
"and cross-backend smoke validation"
|
| 189 |
+
],
|
| 190 |
+
"performance_metrics": {
|
| 191 |
+
"memory_usage_mb": 0,
|
| 192 |
+
"cpu_usage_percent": 0,
|
| 193 |
+
"response_time_ms": 0,
|
| 194 |
+
"throughput_requests_per_second": 0
|
| 195 |
+
},
|
| 196 |
+
"deployment_info": {
|
| 197 |
+
"supported_platforms": [
|
| 198 |
+
"Linux",
|
| 199 |
+
"Windows",
|
| 200 |
+
"macOS"
|
| 201 |
+
],
|
| 202 |
+
"python_versions": [
|
| 203 |
+
"3.8",
|
| 204 |
+
"3.9",
|
| 205 |
+
"3.10",
|
| 206 |
+
"3.11",
|
| 207 |
+
"3.12"
|
| 208 |
+
],
|
| 209 |
+
"deployment_methods": [
|
| 210 |
+
"Docker",
|
| 211 |
+
"pip",
|
| 212 |
+
"conda"
|
| 213 |
+
],
|
| 214 |
+
"monitoring_support": true,
|
| 215 |
+
"logging_configuration": "structured"
|
| 216 |
+
},
|
| 217 |
+
"execution_analysis": {
|
| 218 |
+
"success_factors": [
|
| 219 |
+
"Workflow status is success with all planned nodes executed end-to-end (download, analysis, env, generate, run, review, finalize).",
|
| 220 |
+
"Import-first adapter strategy was feasible (import_feasibility 0.82) and MCP plugin started healthy over stdio.",
|
| 221 |
+
"Repository ingestion succeeded via zip fallback despite DeepWiki failure, allowing static AST-based discovery and generation.",
|
| 222 |
+
"No runtime errors or warnings were recorded in the workflow."
|
| 223 |
+
],
|
| 224 |
+
"failure_reasons": [
|
| 225 |
+
"No hard workflow failure occurred.",
|
| 226 |
+
"Quality-gap failures: original project tests not executed/passed (reported passed=false with empty details) and MCP test evidence is minimal.",
|
| 227 |
+
"DeepWiki analysis failed, reducing external contextual enrichment.",
|
| 228 |
+
"Generated MCP surface appears over-broad and potentially noisy (very large endpoint list, collisions like repeated params/softmax)."
|
| 229 |
+
],
|
| 230 |
+
"overall_assessment": "good",
|
| 231 |
+
"node_performance": {
|
| 232 |
+
"download_time": "Completed successfully; repository imported via zip fallback. No per-node timing provided, but download was not a blocker.",
|
| 233 |
+
"analysis_time": "Likely dominant phase due to AST scan across ~997 files and large symbol extraction; completed without errors.",
|
| 234 |
+
"generation_time": "Completed and produced 7 MCP artifacts; generation appears fast relative to deep analysis, but exact timing unavailable.",
|
| 235 |
+
"test_time": "Plugin health check passed, but substantive test execution is effectively absent (original tests empty), so validation depth is low."
|
| 236 |
+
},
|
| 237 |
+
"resource_usage": {
|
| 238 |
+
"memory_efficiency": "Unknown/insufficient telemetry (reported 0 MB). Instrumentation gap prevents assessment.",
|
| 239 |
+
"cpu_efficiency": "Unknown/insufficient telemetry (reported 0%). Instrumentation gap prevents assessment.",
|
| 240 |
+
"disk_usage": "Generated output footprint reported as 0 size/0 LOC, likely a metrics collection defect rather than true zero usage."
|
| 241 |
+
}
|
| 242 |
+
},
|
| 243 |
+
"technical_quality": {
|
| 244 |
+
"code_quality_score": 74,
|
| 245 |
+
"architecture_score": 78,
|
| 246 |
+
"performance_score": 62,
|
| 247 |
+
"maintainability_score": 70,
|
| 248 |
+
"security_score": 85,
|
| 249 |
+
"scalability_score": 68
|
| 250 |
+
}
|
| 251 |
+
}
|
deepchem/source/.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
deepchem/source/.pre-commit-config.yaml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
repos:
|
| 2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
| 3 |
+
rev: v3.4.0
|
| 4 |
+
hooks:
|
| 5 |
+
- id: check-merge-conflict
|
| 6 |
+
- id: trailing-whitespace
|
| 7 |
+
- id: end-of-file-fixer
|
| 8 |
+
- id: check-yaml
|
| 9 |
+
|
| 10 |
+
- repo: https://github.com/pre-commit/mirrors-yapf
|
| 11 |
+
rev: v0.32.0
|
| 12 |
+
hooks:
|
| 13 |
+
- id: yapf
|
| 14 |
+
|
| 15 |
+
- repo: https://github.com/PyCQA/flake8
|
| 16 |
+
rev: 3.8.4
|
| 17 |
+
hooks:
|
| 18 |
+
- id: flake8
|
| 19 |
+
args: [--count]
|
| 20 |
+
|
| 21 |
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
| 22 |
+
rev: v0.790
|
| 23 |
+
hooks:
|
| 24 |
+
- id: mypy
|
| 25 |
+
args: [--ignore-missing-imports]
|
deepchem/source/.readthedocs.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# .readthedocs.yml
|
| 2 |
+
# Read the Docs configuration file
|
| 3 |
+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
| 4 |
+
|
| 5 |
+
# Required
|
| 6 |
+
version: 2
|
| 7 |
+
|
| 8 |
+
# Build documentation in the docs/ directory with Sphinx
|
| 9 |
+
sphinx:
|
| 10 |
+
configuration: docs/source/conf.py
|
| 11 |
+
|
| 12 |
+
build:
|
| 13 |
+
os: ubuntu-22.04
|
| 14 |
+
tools:
|
| 15 |
+
python: "3.9"
|
| 16 |
+
|
| 17 |
+
# Optionally build your docs in additional formats such as PDF and ePub
|
| 18 |
+
formats: all
|
| 19 |
+
|
| 20 |
+
# Optionally set the version of Python and requirements required to build your docs
|
| 21 |
+
python:
|
| 22 |
+
install:
|
| 23 |
+
- requirements: docs/requirements.txt
|
deepchem/source/.yapfignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#no need to format .npy files
|
| 2 |
+
*.npy
|
deepchem/source/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributor Covenant Code of Conduct
|
| 2 |
+
|
| 3 |
+
## Our Pledge
|
| 4 |
+
|
| 5 |
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
| 6 |
+
|
| 7 |
+
## Our Standards
|
| 8 |
+
|
| 9 |
+
Examples of behavior that contributes to creating a positive environment include:
|
| 10 |
+
|
| 11 |
+
* Using welcoming and inclusive language
|
| 12 |
+
* Being respectful of differing viewpoints and experiences
|
| 13 |
+
* Gracefully accepting constructive criticism
|
| 14 |
+
* Focusing on what is best for the community
|
| 15 |
+
* Showing empathy towards other community members
|
| 16 |
+
|
| 17 |
+
Examples of unacceptable behavior by participants include:
|
| 18 |
+
|
| 19 |
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
| 20 |
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
| 21 |
+
* Public or private harassment
|
| 22 |
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
| 23 |
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
| 24 |
+
|
| 25 |
+
## Our Responsibilities
|
| 26 |
+
|
| 27 |
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
| 28 |
+
|
| 29 |
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
| 30 |
+
|
| 31 |
+
## Scope
|
| 32 |
+
|
| 33 |
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
| 34 |
+
|
| 35 |
+
## Enforcement
|
| 36 |
+
|
| 37 |
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at rbharath@stanford.edu. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
| 38 |
+
|
| 39 |
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
| 40 |
+
|
| 41 |
+
## Attribution
|
| 42 |
+
|
| 43 |
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
| 44 |
+
|
| 45 |
+
[homepage]: http://contributor-covenant.org
|
| 46 |
+
[version]: http://contributor-covenant.org/version/1/4/
|
deepchem/source/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Table of Contents
|
| 2 |
+
|
| 3 |
+
<!-- toc -->
|
| 4 |
+
- [Contributing to Deepchem](#contributing-to-deepchem)
|
| 5 |
+
- [Getting Started](#getting-started)
|
| 6 |
+
- [Pull Request Process](#pull-request-process)
|
| 7 |
+
- [Coding Conventions](#coding-conventions)
|
| 8 |
+
- [Documentation Conventions](#documentation-conventions)
|
| 9 |
+
- [The Agreement](#the-agreement)
|
| 10 |
+
- [Deepchem Technical Steering Committee](#deepchem-technical-steering-committee)
|
| 11 |
+
<!-- tocstop -->
|
| 12 |
+
|
| 13 |
+
## Contributing to DeepChem
|
| 14 |
+
|
| 15 |
+
We actively encourage community contributions to DeepChem. The first
|
| 16 |
+
place to start getting involved is
|
| 17 |
+
[the tutorials](https://deepchem.readthedocs.io/en/latest/get_started/tutorials.html).
|
| 18 |
+
Afterwards, we encourage contributors to give a shot to improving our documentation.
|
| 19 |
+
While we take effort to provide good docs, there's plenty of room
|
| 20 |
+
for improvement. All docs are hosted on Github, either in `README.md`
|
| 21 |
+
file, or in the `docs/` directory.
|
| 22 |
+
|
| 23 |
+
Once you've got a sense of how the package works, we encourage the use
|
| 24 |
+
of Github issues to discuss more complex changes, raise requests for
|
| 25 |
+
new features or propose changes to the global architecture of DeepChem.
|
| 26 |
+
Once consensus is reached on the issue, please submit a PR with proposed
|
| 27 |
+
modifications. All contributed code to DeepChem will be reviewed by a member
|
| 28 |
+
of the DeepChem team, so please make sure your code style and documentation
|
| 29 |
+
style match our guidelines!
|
| 30 |
+
|
| 31 |
+
### Getting Started
|
| 32 |
+
|
| 33 |
+
To develop DeepChem on your machine, we recommend using Anaconda for managing
|
| 34 |
+
packages. If you want to manage multiple builds of DeepChem, you can make use of
|
| 35 |
+
[conda environments](https://conda.io/projects/conda/en/latest/user-guide/concepts/environments.html)
|
| 36 |
+
to maintain seperate Python package environments, each of which can be tied
|
| 37 |
+
to a specific build of DeepChem. Here are some tips to get started:
|
| 38 |
+
|
| 39 |
+
1. Fork the [DeepChem](https://github.com/deepchem/deepchem/) repository
|
| 40 |
+
and clone the forked repository
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
git clone https://github.com/YOUR-USERNAME/deepchem.git
|
| 44 |
+
cd deepchem
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
1.1. If you already have DeepChem from source, update it by running
|
| 48 |
+
```bash
|
| 49 |
+
git fetch upstream
|
| 50 |
+
git rebase upstream/master
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
2. Set up a new conda environment for DeepChem
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
conda create -n deepchem python=3.8
|
| 57 |
+
conda activate deepchem
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
2.1. DeepChem provides backend support for deep
|
| 61 |
+
learning using tensorflow, pytorch or jax. By default, the deep learning frameworks
|
| 62 |
+
gets installed in CPU. If GPU support is required, make sure CUDA is installed
|
| 63 |
+
and then install the desired deep learning framework before installing DeepChem:
|
| 64 |
+
- [tensorflow](https://www.tensorflow.org/install)
|
| 65 |
+
- [pytorch](https://pytorch.org/get-started/locally/#start-locally)
|
| 66 |
+
- [jax](https://github.com/google/jax#installation)
|
| 67 |
+
|
| 68 |
+
3. Install DeepChem in `develop` mode
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
python setup.py develop
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
This mode will symlink the Python files from current local source tree into
|
| 75 |
+
the Python install. Hence, if you modify a Python file, you do not need to
|
| 76 |
+
reinstall DeepChem again and again.
|
| 77 |
+
|
| 78 |
+
In case you need to reinstall, uninstall DeepChem first by running
|
| 79 |
+
`pip uninstall deepchem` until you see `Warning: Skipping deepchem
|
| 80 |
+
as it is not installed`; run `python setup.py clean` and install in `develop` mode again.
|
| 81 |
+
|
| 82 |
+
Some other tips:
|
| 83 |
+
- Every contribution must pass the unit tests. Some tests are
|
| 84 |
+
[marked](https://docs.pytest.org/en/6.2.x/example/markers.html) with custom
|
| 85 |
+
markers like `@pytest.mark.tensorflow`. This helps mainly in two ways: 1) restricting the tests only
|
| 86 |
+
to the part of code marked with the marker 2) giving
|
| 87 |
+
[flexibility](https://docs.pytest.org/en/6.2.x/example/markers.html) in running
|
| 88 |
+
the unit tests depending on the environment.
|
| 89 |
+
- DeepChem has a number of soft requirements which can be found [here](https://deepchem.readthedocs.io/en/latest/get_started/requirements.html).
|
| 90 |
+
- If a commit is simple and doesn't affect any code (keep in mind that some
|
| 91 |
+
docstrings contain code that is used in tests), you can add `[skip ci]`
|
| 92 |
+
(case sensitive) somewhere in your commit message to [skip all build /
|
| 93 |
+
test steps](https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/). Note that changing the pull request body or title on GitHub itself has no effect.
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
### Pull Request Process
|
| 97 |
+
|
| 98 |
+
Every contribution, must be a pull request and must have adequate time for
|
| 99 |
+
review by other committers.
|
| 100 |
+
|
| 101 |
+
A member of the Technical Steering Committee will review the pull request.
|
| 102 |
+
The default path of every contribution should be to merge. The discussion,
|
| 103 |
+
review, and merge process should be designed as corrections that move the
|
| 104 |
+
contribution into the path to merge. Once there are no more corrections,
|
| 105 |
+
(dissent) changes should merge without further process.
|
| 106 |
+
|
| 107 |
+
On successful merge the author will be added as a member of the DeepChem organization.
|
| 108 |
+
|
| 109 |
+
### Coding Conventions
|
| 110 |
+
|
| 111 |
+
DeepChem uses these tools or styles for keeping our codes healthy.
|
| 112 |
+
|
| 113 |
+
- [YAPF](https://github.com/google/yapf) (code format)
|
| 114 |
+
- [Flake8](https://flake8.pycqa.org/en/latest/) (code style check)
|
| 115 |
+
- [mypy](http://mypy-lang.org/) (type check)
|
| 116 |
+
- [doctest](https://docs.python.org/3/library/doctest.html) (interactive examples)
|
| 117 |
+
- [pytest](https://docs.pytest.org/en/6.2.x/index.html) (unit testing)
|
| 118 |
+
|
| 119 |
+
Before making a PR, please check your codes using them.
|
| 120 |
+
You can confirm how to check your codes from [Coding Conventions](https://deepchem.readthedocs.io/en/latest/development_guide/coding.html).
|
| 121 |
+
|
| 122 |
+
### Document Conventions
|
| 123 |
+
|
| 124 |
+
DeepChem uses [Sphinx](https://www.sphinx-doc.org/en/master/) to build
|
| 125 |
+
[the document](https://deepchem.readthedocs.io/en/latest/index.html).
|
| 126 |
+
The document is automatically built by
|
| 127 |
+
[Numpy style docstrings](https://numpydoc.readthedocs.io/en/latest/format.html#numpydoc-docstring-guide)
|
| 128 |
+
in source codes and [Napoleon extension](http://www.sphinx-doc.org/en/stable/ext/napoleon.html).
|
| 129 |
+
For any changes or modification to source code in a PR, please don't forget to add or modify Numpy style docstrings.
|
| 130 |
+
|
| 131 |
+
## The Agreement
|
| 132 |
+
|
| 133 |
+
Contributor offers to license certain software (a “Contribution” or multiple
|
| 134 |
+
“Contributions”) to DeepChem, and DeepChem agrees to accept said Contributions,
|
| 135 |
+
under the terms of the open source license [The MIT License](https://opensource.org/licenses/MIT)
|
| 136 |
+
|
| 137 |
+
The Contributor understands and agrees that DeepChem shall have the
|
| 138 |
+
irrevocable and perpetual right to make and distribute copies of any Contribution, as
|
| 139 |
+
well as to create and distribute collective works and derivative works of any Contribution,
|
| 140 |
+
under [The MIT License](https://opensource.org/licenses/MIT).
|
| 141 |
+
|
| 142 |
+
DeepChem understands and agrees that Contributor retains copyright in its Contributions.
|
| 143 |
+
Nothing in this Contributor Agreement shall be interpreted to prohibit Contributor
|
| 144 |
+
from licensing its Contributions under different terms from the
|
| 145 |
+
[The MIT License](https://opensource.org/licenses/MIT) or this Contributor Agreement.
|
| 146 |
+
|
| 147 |
+
## DeepChem Technical Steering Committee
|
| 148 |
+
|
| 149 |
+
The Technical Steering Committee admits and oversees all top-level of DeepChem.
|
| 150 |
+
|
| 151 |
+
The TSC exercises autonomy in setting up and maintaining procedures, policies,
|
| 152 |
+
and management and administrative structures as it deems appropriate for the
|
| 153 |
+
maintenance and operation of these projects and resources.
|
| 154 |
+
|
| 155 |
+
Included in the responsibilities of the TSC are:
|
| 156 |
+
|
| 157 |
+
* Managing code and documentation creation and changes for the listed projects and resources
|
| 158 |
+
* Performing code reviews on incoming pull requests and merging suitable code changes.
|
| 159 |
+
* Setting and maintaining standards covering contributions of code, documentation and other materials
|
| 160 |
+
* Managing code and binary releases: types, schedules, frequency, delivery mechanisms
|
| 161 |
+
* Making decisions regarding dependencies of DeepChem, including what those
|
| 162 |
+
dependencies are and how they are bundled with source code and releases
|
| 163 |
+
* Creating new repositories and projects under the deepchem GitHub organization as required
|
| 164 |
+
* Setting overall technical direction for the DeepChem project, including
|
| 165 |
+
high-level goals and low-level specifics regarding features and functionality
|
| 166 |
+
* Setting and maintaining appropriate standards for community discourse via the various
|
| 167 |
+
mediums under TSC control (gitter, facebook, blog)
|
| 168 |
+
|
| 169 |
+
Members of the TSC will meet regularly (over phone or video conferencing)
|
| 170 |
+
to coordinate efforts. Minutes from the TSC meetings will be published publicly on an ongoing basis.
|
| 171 |
+
The current members of the TSC are (alphabetically)
|
| 172 |
+
* Peter Eastman
|
| 173 |
+
* Karl Leswing
|
| 174 |
+
* Bharath Ramsundar
|
| 175 |
+
* Zhenqin Wu
|
| 176 |
+
|
| 177 |
+
If you want to join the technical steering committee, you will need to
|
| 178 |
+
submit an application. The application process is relatively lightweight: submit
|
| 179 |
+
a one page document discussing your past contributions to DeepChem and
|
| 180 |
+
propose potential projects you could commit to working on as a member of the
|
| 181 |
+
steering committee. Note that steering committee membership comes with responsibilities.
|
| 182 |
+
In particular, you will need to commit to spending about 10 hours a
|
| 183 |
+
week working on DeepChem. The committee will review your application, and
|
| 184 |
+
if suitable, will accept you as a probationary member of the TSC. Your
|
| 185 |
+
application will be posted publicly to the DeepChem blog if accepted. Membership
|
| 186 |
+
on the committee will be confirmed after 6 months if you’ve successfully
|
| 187 |
+
implemented some of your proposed projects and demonstrated your ability
|
| 188 |
+
to meet the necessary time commitment.
|
deepchem/source/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2017 PandeLab
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 4 |
+
|
| 5 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 6 |
+
|
| 7 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
deepchem/source/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DeepChem
|
| 2 |
+
|
| 3 |
+
[](https://anaconda.org/conda-forge/deepchem)
|
| 4 |
+
[](https://pypi.org/project/deepchem/)
|
| 5 |
+
[](https://deepchem.readthedocs.io/en/latest/?badge=latest)
|
| 6 |
+
[](https://github.com/deepchem/deepchem/actions?query=workflow%3A%22Test+for+DeepChem+Core%22)
|
| 7 |
+
[](https://github.com/deepchem/deepchem/actions?query=workflow%3A%22Test+for+documents%22)
|
| 8 |
+
[](https://github.com/deepchem/deepchem/actions?query=workflow%3A%22Test+for+build+scripts%22)
|
| 9 |
+
[](https://codecov.io/gh/deepchem/deepchem)
|
| 10 |
+
|
| 11 |
+
[Website](https://deepchem.io/) | [Documentation](https://deepchem.readthedocs.io/en/latest/) | [Colab Tutorial](https://github.com/deepchem/deepchem/tree/master/examples/tutorials) | [Discussion Forum](https://forum.deepchem.io/) | [Discord](https://discord.gg/cGzwCdrUqS) | [Model Wishlist](https://github.com/deepchem/deepchem/issues/2680) | [Tutorial Wishlist](https://github.com/deepchem/deepchem/issues/2907)
|
| 12 |
+
|
| 13 |
+
DeepChem aims to provide a high quality open-source toolchain
|
| 14 |
+
that democratizes the use of deep-learning in drug discovery,
|
| 15 |
+
materials science, quantum chemistry, and biology.
|
| 16 |
+
|
| 17 |
+
### Table of contents:
|
| 18 |
+
|
| 19 |
+
- [Requirements](#requirements)
|
| 20 |
+
- [Installation](#installation)
|
| 21 |
+
- [Stable version](#stable-version)
|
| 22 |
+
- [Nightly build version](#nightly-build-version)
|
| 23 |
+
- [Docker](#docker)
|
| 24 |
+
- [From source](#from-source)
|
| 25 |
+
- [From source lightweight](#from-source-lightweight)
|
| 26 |
+
- [Getting Started](#getting-started)
|
| 27 |
+
- [Discord](#discord)
|
| 28 |
+
- [About Us](#about-us)
|
| 29 |
+
- [Contributing to DeepChem](/CONTRIBUTING.md)
|
| 30 |
+
- [Citing DeepChem](#citing-deepchem)
|
| 31 |
+
|
| 32 |
+
## Requirements
|
| 33 |
+
|
| 34 |
+
DeepChem currently supports Python 3.7 through 3.10 and requires these packages on any condition.
|
| 35 |
+
|
| 36 |
+
- [joblib](https://pypi.python.org/pypi/joblib)
|
| 37 |
+
- [NumPy](https://numpy.org/)
|
| 38 |
+
- [pandas](http://pandas.pydata.org/)
|
| 39 |
+
- [scikit-learn](https://scikit-learn.org/stable/)
|
| 40 |
+
- [SciPy](https://www.scipy.org/)
|
| 41 |
+
- [rdkit](https://www.rdkit.org/)
|
| 42 |
+
|
| 43 |
+
### Soft Requirements
|
| 44 |
+
|
| 45 |
+
DeepChem has a number of "soft" requirements.
|
| 46 |
+
If you face some errors like `ImportError: This class requires XXXX`, you may need to install some packages.
|
| 47 |
+
|
| 48 |
+
Please check [the document](https://deepchem.readthedocs.io/en/latest/requirements.html#soft-requirements) about soft requirements.
|
| 49 |
+
|
| 50 |
+
## Installation
|
| 51 |
+
|
| 52 |
+
### Stable version
|
| 53 |
+
|
| 54 |
+
DeepChem stable version can be installed using pip or conda as
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
pip install deepchem
|
| 58 |
+
```
|
| 59 |
+
or
|
| 60 |
+
```
|
| 61 |
+
conda install -c conda-forge deepchem
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
Deepchem provides support for tensorflow, pytorch, jax and each require
|
| 65 |
+
a individual pip Installation.
|
| 66 |
+
|
| 67 |
+
For using models with tensorflow dependencies, you install using
|
| 68 |
+
|
| 69 |
+
```bash
|
| 70 |
+
pip install deepchem[tensorflow]
|
| 71 |
+
```
|
| 72 |
+
For using models with torch dependencies, you install using
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
pip install deepchem[torch]
|
| 76 |
+
```
|
| 77 |
+
For using models with jax dependencies, you install using
|
| 78 |
+
|
| 79 |
+
```bash
|
| 80 |
+
pip install deepchem[jax]
|
| 81 |
+
```
|
| 82 |
+
If GPU support is required, then make sure CUDA is installed and then install the desired deep learning framework using the links below before installing deepchem
|
| 83 |
+
|
| 84 |
+
1. tensorflow - just cuda installed
|
| 85 |
+
2. pytorch - https://pytorch.org/get-started/locally/#start-locally
|
| 86 |
+
3. jax - https://github.com/google/jax#pip-installation-gpu-cuda
|
| 87 |
+
|
| 88 |
+
In `zsh` square brackets are used for globbing/pattern matching. This means you
|
| 89 |
+
need to escape the square brackets in the above installation. You can do so
|
| 90 |
+
by including the dependencies in quotes like `pip install --pre 'deepchem[jax]'`
|
| 91 |
+
|
| 92 |
+
### Nightly build version
|
| 93 |
+
The nightly version is built by the HEAD of DeepChem. It can be installed using
|
| 94 |
+
|
| 95 |
+
```bash
|
| 96 |
+
pip install --pre deepchem
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### Docker
|
| 100 |
+
|
| 101 |
+
If you want to install deepchem using a docker, you can pull two kinds of images.
|
| 102 |
+
DockerHub : https://hub.docker.com/repository/docker/deepchemio/deepchem
|
| 103 |
+
|
| 104 |
+
- `deepchemio/deepchem:x.x.x`
|
| 105 |
+
- Image built by using a conda (x.x.x is a version of deepchem)
|
| 106 |
+
- The x.x.x image is built when we push x.x.x. tag
|
| 107 |
+
- Dockerfile is put in `docker/tag` directory
|
| 108 |
+
- `deepchemio/deepchem:latest`
|
| 109 |
+
- Image built from source codes
|
| 110 |
+
- The latest image is built every time we commit to the master branch
|
| 111 |
+
- Dockerfile is put in `docker/nightly` directory
|
| 112 |
+
|
| 113 |
+
You pull the image like this.
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
docker pull deepchemio/deepchem:2.4.0
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
If you want to know docker usages with deepchem in more detail, please check [the document](https://deepchem.readthedocs.io/en/latest/installation.html#docker).
|
| 120 |
+
|
| 121 |
+
### From source
|
| 122 |
+
|
| 123 |
+
If you try install all soft dependencies at once or contribute to deepchem, we recommend you should install deepchem from source.
|
| 124 |
+
|
| 125 |
+
Please check [this introduction](https://deepchem.readthedocs.io/en/latest/installation.html#from-source-with-conda).
|
| 126 |
+
|
| 127 |
+
## Getting Started
|
| 128 |
+
|
| 129 |
+
The DeepChem project maintains an extensive collection of [tutorials](https://github.com/deepchem/deepchem/tree/master/examples/tutorials). All tutorials are designed to be run on Google colab (or locally if you prefer). Tutorials are arranged in a suggested learning sequence which will take you from beginner to proficient at molecular machine learning and computational biology more broadly.
|
| 130 |
+
|
| 131 |
+
After working through the tutorials, you can also go through other [examples](https://github.com/deepchem/deepchem/tree/master/examples). To apply `deepchem` to a new problem, try starting from one of the existing examples or tutorials and modifying it step by step to work with your new use-case. If you have questions or comments you can raise them on our [gitter](https://gitter.im/deepchem/Lobby).
|
| 132 |
+
|
| 133 |
+
### Supported Integrations
|
| 134 |
+
|
| 135 |
+
- [Weights & Biases](https://docs.wandb.ai/guides/integrations/other/deepchem): Track your DeepChem model's training and evaluation metrics.
|
| 136 |
+
|
| 137 |
+
### Discord
|
| 138 |
+
|
| 139 |
+
The DeepChem [Discord](https://discord.gg/cGzwCdrUqS) hosts a number of scientists, developers, and enthusiasts interested in deep learning for the life sciences. Probably the easiest place to ask simple questions or float requests for new features.
|
| 140 |
+
|
| 141 |
+
## About Us
|
| 142 |
+
|
| 143 |
+
DeepChem is managed by a team of open source contributors. Anyone is free to join and contribute!
|
| 144 |
+
|
| 145 |
+
## Citing DeepChem
|
| 146 |
+
|
| 147 |
+
If you have used DeepChem in the course of your research, we ask that you cite the "Deep Learning for the Life Sciences" book by the DeepChem core team.
|
| 148 |
+
|
| 149 |
+
To cite this book, please use this bibtex entry:
|
| 150 |
+
|
| 151 |
+
```
|
| 152 |
+
@book{Ramsundar-et-al-2019,
|
| 153 |
+
title={Deep Learning for the Life Sciences},
|
| 154 |
+
author={Bharath Ramsundar and Peter Eastman and Patrick Walters and Vijay Pande and Karl Leswing and Zhenqin Wu},
|
| 155 |
+
publisher={O'Reilly Media},
|
| 156 |
+
note={\url{https://www.amazon.com/Deep-Learning-Life-Sciences-Microscopy/dp/1492039837}},
|
| 157 |
+
year={2019}
|
| 158 |
+
}
|
| 159 |
+
```
|
deepchem/source/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
deepchem Project Package Initialization File
|
| 4 |
+
"""
|
deepchem/source/contrib/DeepMHC/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
deepchem/source/contrib/DeepMHC/bd13_datasets.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""BD2013 dataset loader to be used with DeepMHC."""
|
| 2 |
+
|
| 3 |
+
from __future__ import division
|
| 4 |
+
from __future__ import print_function
|
| 5 |
+
|
| 6 |
+
__author__ = "Vignesh Ram Somnath"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import os
|
| 11 |
+
import logging
|
| 12 |
+
|
| 13 |
+
import deepchem as dc
|
| 14 |
+
|
| 15 |
+
DATASET_URL = "http://tools.iedb.org/static/main/binding_data_2013.zip"
|
| 16 |
+
FILE_NAME = "bdata.20130222.mhci.txt"
|
| 17 |
+
|
| 18 |
+
TEST_FILES = [
|
| 19 |
+
"2016-12-09", "2016-05-03", "2016-02-19", "2015-08-07", "2015-07-31",
|
| 20 |
+
"2015-07-17", "2015-06-26", "2015-06-19", "2015-05-15", "2015-02-06",
|
| 21 |
+
"2015-01-16", "2014-10-31", "2014-06-20", "2014-05-23", "2014-03-28",
|
| 22 |
+
"2014-03-21"
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
TEST_URLS = [
|
| 26 |
+
"http://tools.iedb.org/auto_bench/mhci/weekly/accumulated/" + str(date) +
|
| 27 |
+
"/predictions" for date in TEST_FILES
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger(__name__)
|
| 31 |
+
|
| 32 |
+
aa_charset = [
|
| 33 |
+
"A", "R", "N", "D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F", "P",
|
| 34 |
+
"S", "T", "W", "Y", "V"
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def to_one_hot_array(sequence):
|
| 39 |
+
"""Converts the sequence to one-hot-array."""
|
| 40 |
+
one_hot_array = list()
|
| 41 |
+
for letter in sequence:
|
| 42 |
+
one_hot_array.append([letter == i for i in aa_charset])
|
| 43 |
+
return np.asarray(one_hot_array, dtype=np.int32)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def featurize(sequences, pad_length=13):
|
| 47 |
+
"""One-hot encoding for sequences with padding."""
|
| 48 |
+
features = list()
|
| 49 |
+
for sequence in sequences:
|
| 50 |
+
one_hot_seq = to_one_hot_array(sequence)
|
| 51 |
+
num_to_pad = pad_length - len(sequence)
|
| 52 |
+
if num_to_pad % 2 == 0:
|
| 53 |
+
one_hot_seq = np.pad(
|
| 54 |
+
one_hot_seq, [(int(num_to_pad / 2), int(num_to_pad / 2)), (0, 0)],
|
| 55 |
+
mode='constant')
|
| 56 |
+
else:
|
| 57 |
+
one_hot_seq = np.pad(
|
| 58 |
+
one_hot_seq, [(int((num_to_pad + 1) / 2), int((num_to_pad - 1) / 2)),
|
| 59 |
+
(0, 0)],
|
| 60 |
+
mode='constant')
|
| 61 |
+
features.append(one_hot_seq)
|
| 62 |
+
features = np.asarray(features)
|
| 63 |
+
return features
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def load_bd2013_human(mhc_allele="HLA-A*02:01",
|
| 67 |
+
seq_len=9,
|
| 68 |
+
pad_len=13,
|
| 69 |
+
test_measure_type="ic50",
|
| 70 |
+
reload=True):
|
| 71 |
+
"""Loads the human specific data from the bd2013 dataset."""
|
| 72 |
+
bd13_tasks = ["-log(IC50)"]
|
| 73 |
+
|
| 74 |
+
data_dir = dc.utils.get_data_dir()
|
| 75 |
+
save_dir = os.path.join(data_dir, "bd13", mhc_allele, str(seq_len))
|
| 76 |
+
train_dir = os.path.join(save_dir, "train_dir")
|
| 77 |
+
test_dir = os.path.join(save_dir, "test_dir")
|
| 78 |
+
|
| 79 |
+
# TODO (VIGS25): Account for the reload option
|
| 80 |
+
|
| 81 |
+
# Downloading train files
|
| 82 |
+
train_file = os.path.join(data_dir, "binding_data_2013.zip")
|
| 83 |
+
if not os.path.exists(train_file):
|
| 84 |
+
logger.info("Downloading Binding data...")
|
| 85 |
+
dc.utils.download_url(url=DATASET_URL, dest_dir=data_dir)
|
| 86 |
+
if os.path.exists(train_dir):
|
| 87 |
+
logger.info("Directory for training data already exists")
|
| 88 |
+
else:
|
| 89 |
+
logger.info("Unzipping full dataset...")
|
| 90 |
+
dc.utils.unzip_file(file=train_file, dest_dir=data_dir)
|
| 91 |
+
|
| 92 |
+
# Parsing training data
|
| 93 |
+
train_labels = list()
|
| 94 |
+
train_sequences = list()
|
| 95 |
+
with open(os.path.join(data_dir, FILE_NAME), "r") as f:
|
| 96 |
+
for line in f.readlines():
|
| 97 |
+
elements = line.strip().split("\t")
|
| 98 |
+
# Pick only sequences from humans, belong to specific MHC allele and having given seq_len
|
| 99 |
+
if elements[0] == "human" and elements[1] == mhc_allele and int(
|
| 100 |
+
elements[2]) == seq_len:
|
| 101 |
+
train_sequences.append(elements[3])
|
| 102 |
+
train_labels.append(float(elements[-1]))
|
| 103 |
+
|
| 104 |
+
# Test Files loading
|
| 105 |
+
test_labels = list()
|
| 106 |
+
test_sequences = list()
|
| 107 |
+
test_check_file = os.path.join(data_dir, TEST_FILES[0] + '_predictions.tsv')
|
| 108 |
+
if not os.path.exists(test_check_file):
|
| 109 |
+
for index, filename in enumerate(TEST_FILES):
|
| 110 |
+
test_url = TEST_URLS[index]
|
| 111 |
+
test_filename = filename + '_predictions.tsv'
|
| 112 |
+
dc.utils.download_url(url=test_url, dest_dir=data_dir, name=test_filename)
|
| 113 |
+
|
| 114 |
+
for filename in TEST_FILES:
|
| 115 |
+
test_filename = os.path.join(data_dir, filename + '_predictions.tsv')
|
| 116 |
+
with open(test_filename, 'r') as f:
|
| 117 |
+
for line in f.readlines():
|
| 118 |
+
elements = line.strip().split("\t")
|
| 119 |
+
if len(elements) == 1:
|
| 120 |
+
continue
|
| 121 |
+
if elements[2] == mhc_allele and int(
|
| 122 |
+
elements[3]) == seq_len and elements[4] == test_measure_type:
|
| 123 |
+
test_sequences.append(elements[5])
|
| 124 |
+
test_labels.append(float(elements[6]))
|
| 125 |
+
|
| 126 |
+
# One Hot Featurization
|
| 127 |
+
logger.info("Featurizing training data...")
|
| 128 |
+
train_features = featurize(train_sequences, pad_length=pad_len)
|
| 129 |
+
train_labels = np.array(train_labels).astype(np.float32)
|
| 130 |
+
train_labels = np.expand_dims(train_labels, axis=1)
|
| 131 |
+
|
| 132 |
+
logger.info("Featurizing test data...")
|
| 133 |
+
test_features = featurize(test_sequences, pad_length=pad_len)
|
| 134 |
+
test_labels = np.array(test_labels).astype(np.float32)
|
| 135 |
+
test_labels = np.expand_dims(test_labels, axis=1)
|
| 136 |
+
|
| 137 |
+
train_dataset = dc.data.DiskDataset.from_numpy(train_features, train_labels)
|
| 138 |
+
test_dataset = dc.data.DiskDataset.from_numpy(test_features, test_labels)
|
| 139 |
+
|
| 140 |
+
train_dataset.move(new_data_dir=train_dir)
|
| 141 |
+
test_dataset.move(new_data_dir=test_dir)
|
| 142 |
+
|
| 143 |
+
logger.info("Featurization complete.")
|
| 144 |
+
|
| 145 |
+
transformers = []
|
| 146 |
+
for transformer in transformers:
|
| 147 |
+
train_dataset = transformer.transform(train_dataset)
|
| 148 |
+
test_dataset = transformer.transform(test_dataset)
|
| 149 |
+
|
| 150 |
+
return bd13_tasks, (train_dataset, None, test_dataset), transformers
|
deepchem/source/contrib/DeepMHC/deepmhc.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""DeepMHC model, found in https://www.biorxiv.org/content/early/2017/12/24/239236"""
|
| 2 |
+
|
| 3 |
+
from __future__ import division
|
| 4 |
+
from __future__ import unicode_literals
|
| 5 |
+
|
| 6 |
+
__author__ = "Vignesh Ram Somnath"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import tensorflow as tf
|
| 11 |
+
|
| 12 |
+
from deepchem.data import NumpyDataset
|
| 13 |
+
from deepchem.models.tensorgraph.tensor_graph import TensorGraph
|
| 14 |
+
from deepchem.models.tensorgraph.layers import Conv1D, MaxPool1D, Dense, Dropout
|
| 15 |
+
from deepchem.models.tensorgraph.layers import Flatten
|
| 16 |
+
from deepchem.models.tensorgraph.layers import Feature, Weights, Label
|
| 17 |
+
from deepchem.models.tensorgraph.layers import L2Loss, WeightedError
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class DeepMHC(TensorGraph):
|
| 21 |
+
|
| 22 |
+
name = ['DeepMHC']
|
| 23 |
+
|
| 24 |
+
def __init__(self,
|
| 25 |
+
batch_size=64,
|
| 26 |
+
pad_length=13,
|
| 27 |
+
dropout_p=0.5,
|
| 28 |
+
num_amino_acids=20,
|
| 29 |
+
mode="regression",
|
| 30 |
+
**kwargs):
|
| 31 |
+
|
| 32 |
+
assert mode in ["regression", "classification"]
|
| 33 |
+
self.mode = mode
|
| 34 |
+
self.batch_size = batch_size
|
| 35 |
+
self.dropout_p = dropout_p
|
| 36 |
+
self.pad_length = pad_length
|
| 37 |
+
self.num_amino_acids = num_amino_acids
|
| 38 |
+
super(DeepMHC, self).__init__(**kwargs)
|
| 39 |
+
self._build_graph()
|
| 40 |
+
|
| 41 |
+
def _build_graph(self):
|
| 42 |
+
|
| 43 |
+
self.one_hot_seq = Feature(
|
| 44 |
+
shape=(None, self.pad_length, self.num_amino_acids), dtype=tf.float32)
|
| 45 |
+
|
| 46 |
+
conv1 = Conv1D(kernel_size=2, filters=512, in_layers=[self.one_hot_seq])
|
| 47 |
+
|
| 48 |
+
maxpool1 = MaxPool1D(strides=2, padding="VALID", in_layers=[conv1])
|
| 49 |
+
conv2 = Conv1D(kernel_size=3, filters=512, in_layers=[maxpool1])
|
| 50 |
+
flattened = Flatten(in_layers=[conv2])
|
| 51 |
+
dense1 = Dense(
|
| 52 |
+
out_channels=400, in_layers=[flattened], activation_fn=tf.nn.tanh)
|
| 53 |
+
dropout = Dropout(dropout_prob=self.dropout_p, in_layers=[dense1])
|
| 54 |
+
output = Dense(out_channels=1, in_layers=[dropout], activation_fn=None)
|
| 55 |
+
self.add_output(output)
|
| 56 |
+
|
| 57 |
+
if self.mode == "regression":
|
| 58 |
+
label = Label(shape=(None, 1))
|
| 59 |
+
loss = L2Loss(in_layers=[label, output])
|
| 60 |
+
else:
|
| 61 |
+
raise NotImplementedError(
|
| 62 |
+
"Classification support not added yet. Missing details in paper.")
|
| 63 |
+
weights = Weights(shape=(None,))
|
| 64 |
+
weighted_loss = WeightedError(in_layers=[loss, weights])
|
| 65 |
+
self.set_loss(weighted_loss)
|
| 66 |
+
|
| 67 |
+
def default_generator(self,
|
| 68 |
+
dataset,
|
| 69 |
+
epochs=1,
|
| 70 |
+
predict=False,
|
| 71 |
+
deterministic=True,
|
| 72 |
+
pad_batches=True):
|
| 73 |
+
|
| 74 |
+
for epoch in range(epochs):
|
| 75 |
+
for (X_b, y_b, w_b,
|
| 76 |
+
ids_b) in dataset.iterbatches(batch_size=self.batch_size):
|
| 77 |
+
feed_dict = {}
|
| 78 |
+
feed_dict[self.one_hot_seq] = X_b
|
| 79 |
+
if y_b is not None:
|
| 80 |
+
feed_dict[self.labels[0]] = -np.log10(y_b)
|
| 81 |
+
if w_b is not None and not predict:
|
| 82 |
+
feed_dict[self.task_weights[0]] = w_b
|
| 83 |
+
|
| 84 |
+
yield feed_dict
|
| 85 |
+
|
| 86 |
+
def predict_on_batch(self, X, transformers=[], outputs=None):
|
| 87 |
+
dataset = NumpyDataset(X, y=None)
|
| 88 |
+
generator = self.default_generator(dataset, predict=True, pad_batches=False)
|
| 89 |
+
preds = self.predict_on_generator(generator, transformers, outputs)
|
| 90 |
+
preds = 10**-preds # Since we get train on -log10(IC50)
|
| 91 |
+
return preds
|
| 92 |
+
|
| 93 |
+
def create_estimator_inputs(self, feature_columns, weight_column, features,
|
| 94 |
+
labels, mode):
|
| 95 |
+
tensors = dict()
|
| 96 |
+
for layer, column in zip(self.features, feature_columns):
|
| 97 |
+
feature_column = tf.feature_column.input_layer(features, [column])
|
| 98 |
+
if feature_column.dtype != column.dtype:
|
| 99 |
+
feature_column = tf.cast(feature_column, column.dtype)
|
| 100 |
+
tensors[layer] = feature_column
|
| 101 |
+
if weight_column is not None:
|
| 102 |
+
tensors[self.task_weights[0]] = tf.feature_column.input_layer(
|
| 103 |
+
features, [weight_column])
|
| 104 |
+
if labels is not None:
|
| 105 |
+
tensors[self.labels[[0]]] = labels
|
| 106 |
+
|
| 107 |
+
return tensors
|
deepchem/source/contrib/DeepMHC/run_deepmhc.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Script to train DeepMHC model on the BD2013 dataset.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import print_function
|
| 6 |
+
from __future__ import division
|
| 7 |
+
from __future__ import unicode_literals
|
| 8 |
+
|
| 9 |
+
from bd13_datasets import aa_charset, load_bd2013_human
|
| 10 |
+
from deepmhc import DeepMHC
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import deepchem as dc
|
| 14 |
+
from scipy.stats import spearmanr
|
| 15 |
+
|
| 16 |
+
# Args
|
| 17 |
+
pad_len = 13
|
| 18 |
+
num_amino_acids = len(aa_charset)
|
| 19 |
+
mhc_allele = "HLA-A*02:01"
|
| 20 |
+
dropout_p = 0.5
|
| 21 |
+
batch_size = 64
|
| 22 |
+
nb_epochs = 100
|
| 23 |
+
|
| 24 |
+
tasks, datasets, transformers = load_bd2013_human(
|
| 25 |
+
mhc_allele=mhc_allele, seq_len=9, pad_len=pad_len)
|
| 26 |
+
metric = dc.metrics.Metric(metric=dc.metrics.pearsonr, mode="regression")
|
| 27 |
+
|
| 28 |
+
train_dataset, _, test_dataset = datasets
|
| 29 |
+
model = DeepMHC(num_amino_acids=num_amino_acids, pad_length=pad_len)
|
| 30 |
+
|
| 31 |
+
model.fit(train_dataset, nb_epoch=nb_epochs)
|
| 32 |
+
|
| 33 |
+
print("Evaluating models...")
|
| 34 |
+
train_scores = model.evaluate(train_dataset, [metric], transformers)
|
| 35 |
+
test_scores = model.evaluate(test_dataset, [metric], transformers)
|
| 36 |
+
|
| 37 |
+
print("Train scores")
|
| 38 |
+
print(train_scores['pearsonr'])
|
| 39 |
+
|
| 40 |
+
print("Test scores")
|
| 41 |
+
print(test_scores['pearsonr'])
|
deepchem/source/contrib/DiabeticRetinopathy/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
deepchem/source/contrib/DiabeticRetinopathy/data.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Diabetic Retinopathy Images loader.
|
| 3 |
+
"""
|
| 4 |
+
from __future__ import division
|
| 5 |
+
from __future__ import unicode_literals
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import logging
|
| 9 |
+
import deepchem
|
| 10 |
+
import numpy as np
|
| 11 |
+
import pandas as pd
|
| 12 |
+
|
| 13 |
+
logger = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def load_images_DR(split='random', seed=None):
|
| 17 |
+
""" Loader for DR images """
|
| 18 |
+
data_dir = deepchem.utils.get_data_dir()
|
| 19 |
+
images_path = os.path.join(data_dir, 'DR', 'train')
|
| 20 |
+
label_path = os.path.join(data_dir, 'DR', 'trainLabels.csv')
|
| 21 |
+
if not os.path.exists(images_path) or not os.path.exists(label_path):
|
| 22 |
+
logger.warn("Cannot locate data, \n\
|
| 23 |
+
all images(.png) should be stored in the folder: $DEEPCHEM_DATA_DIR/DR/train/,\n\
|
| 24 |
+
corresponding label file should be stored as $DEEPCHEM_DATA_DIR/DR/trainLabels.csv.\n\
|
| 25 |
+
Please refer to https://www.kaggle.com/c/diabetic-retinopathy-detection for data access"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
image_names = os.listdir(images_path)
|
| 29 |
+
raw_images = []
|
| 30 |
+
for im in image_names:
|
| 31 |
+
if im.endswith('.jpeg') and not im.startswith(
|
| 32 |
+
'cut_') and not 'cut_' + im in image_names:
|
| 33 |
+
raw_images.append(im)
|
| 34 |
+
if len(raw_images) > 0:
|
| 35 |
+
cut_raw_images(raw_images, images_path)
|
| 36 |
+
|
| 37 |
+
image_names = [
|
| 38 |
+
p for p in os.listdir(images_path)
|
| 39 |
+
if p.startswith('cut_') and p.endswith('.png')
|
| 40 |
+
]
|
| 41 |
+
all_labels = dict(zip(*np.transpose(np.array(pd.read_csv(label_path)))))
|
| 42 |
+
|
| 43 |
+
print("Number of images: %d" % len(image_names))
|
| 44 |
+
labels = np.array(
|
| 45 |
+
[all_labels[os.path.splitext(n)[0][4:]] for n in image_names]).reshape(
|
| 46 |
+
(-1, 1))
|
| 47 |
+
image_full_paths = [os.path.join(images_path, n) for n in image_names]
|
| 48 |
+
|
| 49 |
+
classes, cts = np.unique(list(all_labels.values()), return_counts=True)
|
| 50 |
+
weight_ratio = dict(zip(classes, np.max(cts) / cts.astype(float)))
|
| 51 |
+
weights = np.array([weight_ratio[l[0]] for l in labels]).reshape((-1, 1))
|
| 52 |
+
|
| 53 |
+
loader = deepchem.data.ImageLoader()
|
| 54 |
+
dat = loader.featurize(
|
| 55 |
+
image_full_paths, labels=labels, weights=weights)
|
| 56 |
+
if split == None:
|
| 57 |
+
return dat
|
| 58 |
+
|
| 59 |
+
splitters = {
|
| 60 |
+
'index': deepchem.splits.IndexSplitter(),
|
| 61 |
+
'random': deepchem.splits.RandomSplitter()
|
| 62 |
+
}
|
| 63 |
+
if not seed is None:
|
| 64 |
+
np.random.seed(seed)
|
| 65 |
+
splitter = splitters[split]
|
| 66 |
+
train, valid, test = splitter.train_valid_test_split(dat)
|
| 67 |
+
all_dataset = (train, valid, test)
|
| 68 |
+
return all_dataset
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def cut_raw_images(all_images, path):
|
| 72 |
+
"""Preprocess images:
|
| 73 |
+
(1) Crop the central square including retina
|
| 74 |
+
(2) Reduce resolution to 512 * 512
|
| 75 |
+
"""
|
| 76 |
+
print("Num of images to be processed: %d" % len(all_images))
|
| 77 |
+
try:
|
| 78 |
+
import cv2
|
| 79 |
+
except:
|
| 80 |
+
logger.warn("OpenCV required for image preprocessing")
|
| 81 |
+
return
|
| 82 |
+
|
| 83 |
+
for i, img_path in enumerate(all_images):
|
| 84 |
+
if i % 100 == 0:
|
| 85 |
+
print("on image %d" % i)
|
| 86 |
+
if os.path.join(path, 'cut_' + os.path.splitext(img_path)[0] + '.png'):
|
| 87 |
+
continue
|
| 88 |
+
img = cv2.imread(os.path.join(path, img_path))
|
| 89 |
+
edges = cv2.Canny(img, 10, 30)
|
| 90 |
+
coords = zip(*np.where(edges > 0))
|
| 91 |
+
n_p = len(coords)
|
| 92 |
+
|
| 93 |
+
coords.sort(key=lambda x: (x[0], x[1]))
|
| 94 |
+
center_0 = int(
|
| 95 |
+
(coords[int(0.01 * n_p)][0] + coords[int(0.99 * n_p)][0]) / 2)
|
| 96 |
+
coords.sort(key=lambda x: (x[1], x[0]))
|
| 97 |
+
center_1 = int(
|
| 98 |
+
(coords[int(0.01 * n_p)][1] + coords[int(0.99 * n_p)][1]) / 2)
|
| 99 |
+
|
| 100 |
+
edge_size = min(
|
| 101 |
+
[center_0, img.shape[0] - center_0, center_1, img.shape[1] - center_1])
|
| 102 |
+
img_cut = img[(center_0 - edge_size):(center_0 + edge_size), (
|
| 103 |
+
center_1 - edge_size):(center_1 + edge_size)]
|
| 104 |
+
img_cut = cv2.resize(img_cut, (512, 512))
|
| 105 |
+
cv2.imwrite(
|
| 106 |
+
os.path.join(path, 'cut_' + os.path.splitext(img_path)[0] + '.png'),
|
| 107 |
+
img_cut)
|
deepchem/source/contrib/DiabeticRetinopathy/model.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python2
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""
|
| 4 |
+
Created on Mon Sep 10 06:12:10 2018
|
| 5 |
+
|
| 6 |
+
@author: zqwu
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import tensorflow as tf
|
| 11 |
+
|
| 12 |
+
from deepchem.data import NumpyDataset, pad_features
|
| 13 |
+
from deepchem.metrics import to_one_hot
|
| 14 |
+
from deepchem.models.tensorgraph.layers import Layer, Dense, SoftMax, Reshape, \
|
| 15 |
+
SparseSoftMaxCrossEntropy, BatchNorm, Conv2D, MaxPool2D, WeightedError, \
|
| 16 |
+
Dropout, ReLU, Stack, Flatten, ReduceMax, WeightDecay
|
| 17 |
+
from deepchem.models.tensorgraph.layers import L2Loss, Label, Weights, Feature
|
| 18 |
+
from deepchem.models.tensorgraph.tensor_graph import TensorGraph
|
| 19 |
+
from deepchem.trans import undo_transforms
|
| 20 |
+
from deepchem.data.data_loader import ImageLoader
|
| 21 |
+
from sklearn.metrics import confusion_matrix, accuracy_score
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class DRModel(TensorGraph):
|
| 25 |
+
|
| 26 |
+
def __init__(self,
|
| 27 |
+
n_tasks=1,
|
| 28 |
+
image_size=512,
|
| 29 |
+
n_downsample=6,
|
| 30 |
+
n_init_kernel=16,
|
| 31 |
+
n_fully_connected=[1024],
|
| 32 |
+
n_classes=5,
|
| 33 |
+
augment=False,
|
| 34 |
+
**kwargs):
|
| 35 |
+
"""
|
| 36 |
+
Parameters
|
| 37 |
+
----------
|
| 38 |
+
n_tasks: int
|
| 39 |
+
Number of tasks
|
| 40 |
+
image_size: int
|
| 41 |
+
Resolution of the input images(square)
|
| 42 |
+
n_downsample: int
|
| 43 |
+
Downsample ratio in power of 2
|
| 44 |
+
n_init_kernel: int
|
| 45 |
+
Kernel size for the first convolutional layer
|
| 46 |
+
n_fully_connected: list of int
|
| 47 |
+
Shape of FC layers after convolutions
|
| 48 |
+
n_classes: int
|
| 49 |
+
Number of classes to predict (only used in classification mode)
|
| 50 |
+
augment: bool
|
| 51 |
+
If to use data augmentation
|
| 52 |
+
"""
|
| 53 |
+
self.n_tasks = n_tasks
|
| 54 |
+
self.image_size = image_size
|
| 55 |
+
self.n_downsample = n_downsample
|
| 56 |
+
self.n_init_kernel = n_init_kernel
|
| 57 |
+
self.n_fully_connected = n_fully_connected
|
| 58 |
+
self.n_classes = n_classes
|
| 59 |
+
self.augment = augment
|
| 60 |
+
super(DRModel, self).__init__(**kwargs)
|
| 61 |
+
self.build_graph()
|
| 62 |
+
|
| 63 |
+
def build_graph(self):
|
| 64 |
+
# inputs placeholder
|
| 65 |
+
self.inputs = Feature(
|
| 66 |
+
shape=(None, self.image_size, self.image_size, 3), dtype=tf.float32)
|
| 67 |
+
# data preprocessing and augmentation
|
| 68 |
+
in_layer = DRAugment(
|
| 69 |
+
self.augment,
|
| 70 |
+
self.batch_size,
|
| 71 |
+
size=(self.image_size, self.image_size),
|
| 72 |
+
in_layers=[self.inputs])
|
| 73 |
+
# first conv layer
|
| 74 |
+
in_layer = Conv2D(
|
| 75 |
+
self.n_init_kernel,
|
| 76 |
+
kernel_size=7,
|
| 77 |
+
activation_fn=None,
|
| 78 |
+
in_layers=[in_layer])
|
| 79 |
+
in_layer = BatchNorm(in_layers=[in_layer])
|
| 80 |
+
in_layer = ReLU(in_layers=[in_layer])
|
| 81 |
+
|
| 82 |
+
# downsample by max pooling
|
| 83 |
+
res_in = MaxPool2D(
|
| 84 |
+
ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], in_layers=[in_layer])
|
| 85 |
+
|
| 86 |
+
for ct_module in range(self.n_downsample - 1):
|
| 87 |
+
# each module is a residual convolutional block
|
| 88 |
+
# followed by a convolutional downsample layer
|
| 89 |
+
in_layer = Conv2D(
|
| 90 |
+
self.n_init_kernel * 2**(ct_module - 1),
|
| 91 |
+
kernel_size=1,
|
| 92 |
+
activation_fn=None,
|
| 93 |
+
in_layers=[res_in])
|
| 94 |
+
in_layer = BatchNorm(in_layers=[in_layer])
|
| 95 |
+
in_layer = ReLU(in_layers=[in_layer])
|
| 96 |
+
in_layer = Conv2D(
|
| 97 |
+
self.n_init_kernel * 2**(ct_module - 1),
|
| 98 |
+
kernel_size=3,
|
| 99 |
+
activation_fn=None,
|
| 100 |
+
in_layers=[in_layer])
|
| 101 |
+
in_layer = BatchNorm(in_layers=[in_layer])
|
| 102 |
+
in_layer = ReLU(in_layers=[in_layer])
|
| 103 |
+
in_layer = Conv2D(
|
| 104 |
+
self.n_init_kernel * 2**ct_module,
|
| 105 |
+
kernel_size=1,
|
| 106 |
+
activation_fn=None,
|
| 107 |
+
in_layers=[in_layer])
|
| 108 |
+
res_a = BatchNorm(in_layers=[in_layer])
|
| 109 |
+
|
| 110 |
+
res_out = res_in + res_a
|
| 111 |
+
res_in = Conv2D(
|
| 112 |
+
self.n_init_kernel * 2**(ct_module + 1),
|
| 113 |
+
kernel_size=3,
|
| 114 |
+
stride=2,
|
| 115 |
+
in_layers=[res_out])
|
| 116 |
+
res_in = BatchNorm(in_layers=[res_in])
|
| 117 |
+
|
| 118 |
+
# max pooling over the final outcome
|
| 119 |
+
in_layer = ReduceMax(axis=(1, 2), in_layers=[res_in])
|
| 120 |
+
|
| 121 |
+
for layer_size in self.n_fully_connected:
|
| 122 |
+
# fully connected layers
|
| 123 |
+
in_layer = Dense(
|
| 124 |
+
layer_size, activation_fn=tf.nn.relu, in_layers=[in_layer])
|
| 125 |
+
# dropout for dense layers
|
| 126 |
+
#in_layer = Dropout(0.25, in_layers=[in_layer])
|
| 127 |
+
|
| 128 |
+
logit_pred = Dense(
|
| 129 |
+
self.n_tasks * self.n_classes, activation_fn=None, in_layers=[in_layer])
|
| 130 |
+
logit_pred = Reshape(
|
| 131 |
+
shape=(None, self.n_tasks, self.n_classes), in_layers=[logit_pred])
|
| 132 |
+
|
| 133 |
+
weights = Weights(shape=(None, self.n_tasks))
|
| 134 |
+
labels = Label(shape=(None, self.n_tasks), dtype=tf.int32)
|
| 135 |
+
|
| 136 |
+
output = SoftMax(logit_pred)
|
| 137 |
+
self.add_output(output)
|
| 138 |
+
loss = SparseSoftMaxCrossEntropy(in_layers=[labels, logit_pred])
|
| 139 |
+
weighted_loss = WeightedError(in_layers=[loss, weights])
|
| 140 |
+
|
| 141 |
+
# weight decay regularizer
|
| 142 |
+
# weighted_loss = WeightDecay(0.1, 'l2', in_layers=[weighted_loss])
|
| 143 |
+
self.set_loss(weighted_loss)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def DRAccuracy(y, y_pred):
|
| 147 |
+
y_pred = np.argmax(y_pred, 1)
|
| 148 |
+
return accuracy_score(y, y_pred)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def DRSpecificity(y, y_pred):
|
| 152 |
+
y_pred = (np.argmax(y_pred, 1) > 0) * 1
|
| 153 |
+
y = (y > 0) * 1
|
| 154 |
+
TN = sum((1 - y_pred) * (1 - y))
|
| 155 |
+
N = sum(1 - y)
|
| 156 |
+
return float(TN) / N
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def DRSensitivity(y, y_pred):
|
| 160 |
+
y_pred = (np.argmax(y_pred, 1) > 0) * 1
|
| 161 |
+
y = (y > 0) * 1
|
| 162 |
+
TP = sum(y_pred * y)
|
| 163 |
+
P = sum(y)
|
| 164 |
+
return float(TP) / P
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def ConfusionMatrix(y, y_pred):
|
| 168 |
+
y_pred = np.argmax(y_pred, 1)
|
| 169 |
+
return confusion_matrix(y, y_pred)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def QuadWeightedKappa(y, y_pred):
|
| 173 |
+
y_pred = np.argmax(y_pred, 1)
|
| 174 |
+
cm = confusion_matrix(y, y_pred)
|
| 175 |
+
classes_y, counts_y = np.unique(y, return_counts=True)
|
| 176 |
+
classes_y_pred, counts_y_pred = np.unique(y_pred, return_counts=True)
|
| 177 |
+
E = np.zeros((classes_y.shape[0], classes_y.shape[0]))
|
| 178 |
+
for i, c1 in enumerate(classes_y):
|
| 179 |
+
for j, c2 in enumerate(classes_y_pred):
|
| 180 |
+
E[c1, c2] = counts_y[i] * counts_y_pred[j]
|
| 181 |
+
E = E / np.sum(E) * np.sum(cm)
|
| 182 |
+
w = np.zeros((classes_y.shape[0], classes_y.shape[0]))
|
| 183 |
+
for i in range(classes_y.shape[0]):
|
| 184 |
+
for j in range(classes_y.shape[0]):
|
| 185 |
+
w[i, j] = float((i - j)**2) / (classes_y.shape[0] - 1)**2
|
| 186 |
+
re = 1 - np.sum(w * cm) / np.sum(w * E)
|
| 187 |
+
return re
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
class DRAugment(Layer):
|
| 191 |
+
|
| 192 |
+
def __init__(self,
|
| 193 |
+
augment,
|
| 194 |
+
batch_size,
|
| 195 |
+
distort_color=True,
|
| 196 |
+
central_crop=True,
|
| 197 |
+
size=(512, 512),
|
| 198 |
+
**kwargs):
|
| 199 |
+
"""
|
| 200 |
+
Parameters
|
| 201 |
+
----------
|
| 202 |
+
augment: bool
|
| 203 |
+
If to use data augmentation
|
| 204 |
+
batch_size: int
|
| 205 |
+
Number of images in the batch
|
| 206 |
+
distort_color: bool
|
| 207 |
+
If to apply random distortion on the color
|
| 208 |
+
central_crop: bool
|
| 209 |
+
If to randomly crop the sample around the center
|
| 210 |
+
size: int
|
| 211 |
+
Resolution of the input images(square)
|
| 212 |
+
"""
|
| 213 |
+
self.augment = augment
|
| 214 |
+
self.batch_size = batch_size
|
| 215 |
+
self.distort_color = distort_color
|
| 216 |
+
self.central_crop = central_crop
|
| 217 |
+
self.size = size
|
| 218 |
+
super(DRAugment, self).__init__(**kwargs)
|
| 219 |
+
|
| 220 |
+
def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):
|
| 221 |
+
inputs = self._get_input_tensors(in_layers)
|
| 222 |
+
parent_tensor = inputs[0]
|
| 223 |
+
training = kwargs['training'] if 'training' in kwargs else 1.0
|
| 224 |
+
|
| 225 |
+
parent_tensor = parent_tensor / 255.0
|
| 226 |
+
if not self.augment:
|
| 227 |
+
out_tensor = parent_tensor
|
| 228 |
+
else:
|
| 229 |
+
|
| 230 |
+
def preprocess(img):
|
| 231 |
+
img = tf.image.random_flip_left_right(img)
|
| 232 |
+
img = tf.image.random_flip_up_down(img)
|
| 233 |
+
img = tf.image.rot90(img, k=np.random.randint(0, 4))
|
| 234 |
+
if self.distort_color:
|
| 235 |
+
img = tf.image.random_brightness(img, max_delta=32. / 255.)
|
| 236 |
+
img = tf.image.random_saturation(img, lower=0.5, upper=1.5)
|
| 237 |
+
img = tf.clip_by_value(img, 0.0, 1.0)
|
| 238 |
+
if self.central_crop:
|
| 239 |
+
# sample cut ratio from a clipped gaussian
|
| 240 |
+
img = tf.image.central_crop(img,
|
| 241 |
+
np.clip(
|
| 242 |
+
np.random.normal(1., 0.06), 0.8, 1.))
|
| 243 |
+
img = tf.image.resize_bilinear(
|
| 244 |
+
tf.expand_dims(img, 0), tf.convert_to_tensor(self.size))[0]
|
| 245 |
+
return img
|
| 246 |
+
|
| 247 |
+
outs = tf.map_fn(preprocess, parent_tensor)
|
| 248 |
+
# train/valid differences
|
| 249 |
+
out_tensor = training * outs + (1 - training) * parent_tensor
|
| 250 |
+
if set_tensors:
|
| 251 |
+
self.out_tensor = out_tensor
|
| 252 |
+
return out_tensor
|
deepchem/source/contrib/DiabeticRetinopathy/run.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python2
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""
|
| 4 |
+
Created on Mon Sep 10 06:12:11 2018
|
| 5 |
+
|
| 6 |
+
@author: zqwu
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import deepchem as dc
|
| 10 |
+
import numpy as np
|
| 11 |
+
import pandas as pd
|
| 12 |
+
import os
|
| 13 |
+
import logging
|
| 14 |
+
from model import DRModel, DRAccuracy, ConfusionMatrix, QuadWeightedKappa
|
| 15 |
+
from data import load_images_DR
|
| 16 |
+
|
| 17 |
+
train, valid, test = load_images_DR(split='random', seed=123)
|
| 18 |
+
# Define and build model
|
| 19 |
+
model = DRModel(
|
| 20 |
+
n_init_kernel=32,
|
| 21 |
+
batch_size=32,
|
| 22 |
+
learning_rate=1e-5,
|
| 23 |
+
augment=True,
|
| 24 |
+
model_dir='./test_model')
|
| 25 |
+
if not os.path.exists('./test_model'):
|
| 26 |
+
os.mkdir('test_model')
|
| 27 |
+
model.build()
|
| 28 |
+
#model.restore()
|
| 29 |
+
metrics = [
|
| 30 |
+
dc.metrics.Metric(DRAccuracy, mode='classification'),
|
| 31 |
+
dc.metrics.Metric(QuadWeightedKappa, mode='classification')
|
| 32 |
+
]
|
| 33 |
+
cm = [dc.metrics.Metric(ConfusionMatrix, mode='classification')]
|
| 34 |
+
|
| 35 |
+
logger = logging.getLogger('deepchem.models.tensorgraph.tensor_graph')
|
| 36 |
+
logger.setLevel(logging.DEBUG)
|
| 37 |
+
for i in range(10):
|
| 38 |
+
model.fit(train, nb_epoch=10, checkpoint_interval=3512)
|
| 39 |
+
model.evaluate(train, metrics)
|
| 40 |
+
model.evaluate(valid, metrics)
|
| 41 |
+
model.evaluate(valid, cm)
|
| 42 |
+
model.evaluate(test, metrics)
|
| 43 |
+
model.evaluate(test, cm)
|
deepchem/source/contrib/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
deepchem/source/contrib/atomicconv/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
deepchem/source/contrib/atomicconv/acnn/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
deepchem/source/contrib/atomicconv/acnn/core/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
deepchem/source/contrib/atomicconv/acnn/core/get_acnn_core.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
echo "Pulling featurized and split ACNN datasets from deepchem"
|
| 2 |
+
wget http://deepchem.io.s3-website-us-west-1.amazonaws.com/featurized_datasets/acnn_core.tar.gz
|
| 3 |
+
echo "Extracting ACNN datasets"
|
| 4 |
+
tar -zxvf acnn_core.tar.gz
|
deepchem/source/contrib/atomicconv/acnn/core/opt_random.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
__author__ = "Joseph Gomes"
|
| 6 |
+
__copyright__ = "Copyright 2017, Stanford University"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import deepchem as dc
|
| 12 |
+
import numpy as np
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
|
| 15 |
+
sys.path.append("../../models")
|
| 16 |
+
from atomicnet_ops import create_symmetry_parameters
|
| 17 |
+
from atomicnet import TensorflowFragmentRegressor
|
| 18 |
+
|
| 19 |
+
seed = 123
|
| 20 |
+
np.random.seed(seed)
|
| 21 |
+
tf.set_random_seed(seed)
|
| 22 |
+
|
| 23 |
+
base_dir = os.getcwd()
|
| 24 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 25 |
+
train_dir = os.path.join(data_dir, "random_train")
|
| 26 |
+
test_dir = os.path.join(data_dir, "random_test")
|
| 27 |
+
model_dir = os.path.join(base_dir, "random_model")
|
| 28 |
+
|
| 29 |
+
frag1_num_atoms = 70
|
| 30 |
+
frag2_num_atoms = 634
|
| 31 |
+
complex_num_atoms = 701
|
| 32 |
+
max_num_neighbors = 12
|
| 33 |
+
neighbor_cutoff = 12.0
|
| 34 |
+
|
| 35 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 36 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 37 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 38 |
+
transformers = []
|
| 39 |
+
#transformers = [dc.trans.NormalizationTransformer(transform_y=True, dataset=train_dataset)]
|
| 40 |
+
#for transformer in transformers:
|
| 41 |
+
# train_dataset = transformer.transform(train_dataset)
|
| 42 |
+
# test_dataset = transformer.transform(test_dataset)
|
| 43 |
+
|
| 44 |
+
y_train = train_dataset.y
|
| 45 |
+
y_train *= -1 * 2.479 / 4.184
|
| 46 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 47 |
+
train_dataset.X,
|
| 48 |
+
y_train,
|
| 49 |
+
train_dataset.w,
|
| 50 |
+
train_dataset.ids,
|
| 51 |
+
tasks=pdbbind_tasks)
|
| 52 |
+
|
| 53 |
+
y_test = test_dataset.y
|
| 54 |
+
y_test *= -1 * 2.479 / 4.184
|
| 55 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 56 |
+
test_dataset.X,
|
| 57 |
+
y_test,
|
| 58 |
+
test_dataset.w,
|
| 59 |
+
test_dataset.ids,
|
| 60 |
+
tasks=pdbbind_tasks)
|
| 61 |
+
|
| 62 |
+
at = [6, 7., 8., 9., 11., 12., 15., 16., 17., 20., 25., 30., 35., 53.]
|
| 63 |
+
radial = [[
|
| 64 |
+
1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5,
|
| 65 |
+
9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0
|
| 66 |
+
], [0.0, 4.0, 8.0], [0.4]]
|
| 67 |
+
#radial = [[12.0], [0.0, 4.0, 8.0], [0.4]]
|
| 68 |
+
rp = create_symmetry_parameters(radial)
|
| 69 |
+
layer_sizes = [32, 32, 16]
|
| 70 |
+
weight_init_stddevs = [
|
| 71 |
+
1 / np.sqrt(layer_sizes[0]), 1 / np.sqrt(layer_sizes[1]),
|
| 72 |
+
1 / np.sqrt(layer_sizes[2])
|
| 73 |
+
]
|
| 74 |
+
dropouts = [0.3, 0.3, 0.05]
|
| 75 |
+
penalty_type = "l2"
|
| 76 |
+
penalty = 0.
|
| 77 |
+
model = TensorflowFragmentRegressor(
|
| 78 |
+
len(pdbbind_tasks),
|
| 79 |
+
rp,
|
| 80 |
+
at,
|
| 81 |
+
frag1_num_atoms,
|
| 82 |
+
frag2_num_atoms,
|
| 83 |
+
complex_num_atoms,
|
| 84 |
+
max_num_neighbors,
|
| 85 |
+
logdir=model_dir,
|
| 86 |
+
layer_sizes=layer_sizes,
|
| 87 |
+
weight_init_stddevs=weight_init_stddevs,
|
| 88 |
+
bias_init_consts=[0., 0., 0.],
|
| 89 |
+
penalty=penalty,
|
| 90 |
+
penalty_type=penalty_type,
|
| 91 |
+
dropouts=dropouts,
|
| 92 |
+
learning_rate=0.002,
|
| 93 |
+
momentum=0.8,
|
| 94 |
+
optimizer="adam",
|
| 95 |
+
batch_size=24,
|
| 96 |
+
conv_layers=1,
|
| 97 |
+
boxsize=None,
|
| 98 |
+
verbose=True,
|
| 99 |
+
seed=seed)
|
| 100 |
+
model.fit(train_dataset, nb_epoch=10)
|
| 101 |
+
metric = [
|
| 102 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression"),
|
| 103 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression")
|
| 104 |
+
]
|
| 105 |
+
train_evaluator = dc.utils.evaluate.Evaluator(model, train_dataset,
|
| 106 |
+
transformers)
|
| 107 |
+
train_scores = train_evaluator.compute_model_performance(
|
| 108 |
+
metric,
|
| 109 |
+
csv_out="train_predict_ac_random.csv",
|
| 110 |
+
stats_out="train_stats_ac_random.csv")
|
| 111 |
+
print("Train scores")
|
| 112 |
+
print(train_scores)
|
| 113 |
+
test_evaluator = dc.utils.evaluate.Evaluator(model, test_dataset, transformers)
|
| 114 |
+
test_scores = test_evaluator.compute_model_performance(
|
| 115 |
+
metric,
|
| 116 |
+
csv_out="test_predict_ac_random.csv",
|
| 117 |
+
stats_out="test_stats_ac_random.csv")
|
| 118 |
+
print("Test scores")
|
| 119 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/core/opt_random_tensorgraph.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import deepchem as dc
|
| 8 |
+
import numpy as np
|
| 9 |
+
import tensorflow as tf
|
| 10 |
+
from deepchem.models.atomic_conv import atomic_conv_model
|
| 11 |
+
|
| 12 |
+
sys.path.append("../../models")
|
| 13 |
+
from deepchem.models.tensorgraph.layers import Layer, Feature, Label, L2Loss, AtomicConvolution, Transpose, Dense
|
| 14 |
+
from deepchem.models import TensorGraph
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
import tensorflow as tf
|
| 18 |
+
import itertools
|
| 19 |
+
import time
|
| 20 |
+
|
| 21 |
+
seed = 123
|
| 22 |
+
np.random.seed(seed)
|
| 23 |
+
tf.set_random_seed(seed)
|
| 24 |
+
|
| 25 |
+
base_dir = os.getcwd()
|
| 26 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 27 |
+
train_dir = os.path.join(data_dir, "random_train")
|
| 28 |
+
test_dir = os.path.join(data_dir, "random_test")
|
| 29 |
+
model_dir = os.path.join(base_dir, "random_model")
|
| 30 |
+
|
| 31 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 32 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 33 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 34 |
+
transformers = []
|
| 35 |
+
|
| 36 |
+
y_train = train_dataset.y
|
| 37 |
+
y_train *= -1 * 2.479 / 4.184
|
| 38 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 39 |
+
train_dataset.X,
|
| 40 |
+
y_train,
|
| 41 |
+
train_dataset.w,
|
| 42 |
+
train_dataset.ids,
|
| 43 |
+
tasks=pdbbind_tasks)
|
| 44 |
+
|
| 45 |
+
y_test = test_dataset.y
|
| 46 |
+
y_test *= -1 * 2.479 / 4.184
|
| 47 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 48 |
+
test_dataset.X,
|
| 49 |
+
y_test,
|
| 50 |
+
test_dataset.w,
|
| 51 |
+
test_dataset.ids,
|
| 52 |
+
tasks=pdbbind_tasks)
|
| 53 |
+
|
| 54 |
+
batch_size = 24
|
| 55 |
+
tg, feed_dict_generator, label = atomic_conv_model()
|
| 56 |
+
|
| 57 |
+
print("Fitting")
|
| 58 |
+
metric = [
|
| 59 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression"),
|
| 60 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression")
|
| 61 |
+
]
|
| 62 |
+
tg.fit_generator(feed_dict_generator(train_dataset, batch_size, epochs=10))
|
| 63 |
+
|
| 64 |
+
train_evaluator = dc.utils.evaluate.GeneratorEvaluator(
|
| 65 |
+
tg, feed_dict_generator(train_dataset, batch_size), transformers, [label])
|
| 66 |
+
train_scores = train_evaluator.compute_model_performance(metric)
|
| 67 |
+
print("Train scores")
|
| 68 |
+
print(train_scores)
|
| 69 |
+
test_evaluator = dc.utils.evaluate.GeneratorEvaluator(
|
| 70 |
+
tg, feed_dict_generator(test_dataset, batch_size), transformers, [label])
|
| 71 |
+
test_scores = test_evaluator.compute_model_performance(metric)
|
| 72 |
+
print("Test scores")
|
| 73 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/core/opt_scaffold.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
__author__ = "Joseph Gomes"
|
| 6 |
+
__copyright__ = "Copyright 2017, Stanford University"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import deepchem as dc
|
| 12 |
+
import numpy as np
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
|
| 15 |
+
sys.path.append("../../models")
|
| 16 |
+
from atomicnet_ops import create_symmetry_parameters
|
| 17 |
+
from atomicnet import TensorflowFragmentRegressor
|
| 18 |
+
|
| 19 |
+
seed = 123
|
| 20 |
+
np.random.seed(seed)
|
| 21 |
+
tf.set_random_seed(seed)
|
| 22 |
+
|
| 23 |
+
base_dir = os.getcwd()
|
| 24 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 25 |
+
train_dir = os.path.join(data_dir, "scaffold_train")
|
| 26 |
+
test_dir = os.path.join(data_dir, "scaffold_test")
|
| 27 |
+
model_dir = os.path.join(base_dir, "scaffold_model")
|
| 28 |
+
|
| 29 |
+
frag1_num_atoms = 70
|
| 30 |
+
frag2_num_atoms = 634
|
| 31 |
+
complex_num_atoms = 701
|
| 32 |
+
max_num_neighbors = 12
|
| 33 |
+
neighbor_cutoff = 12.0
|
| 34 |
+
|
| 35 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 36 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 37 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 38 |
+
transformers = []
|
| 39 |
+
#transformers = [dc.trans.NormalizationTransformer(transform_y=True, dataset=train_dataset)]
|
| 40 |
+
#for transformer in transformers:
|
| 41 |
+
# train_dataset = transformer.transform(train_dataset)
|
| 42 |
+
# test_dataset = transformer.transform(test_dataset)
|
| 43 |
+
|
| 44 |
+
y_train = train_dataset.y
|
| 45 |
+
y_train *= -1 * 2.479 / 4.184
|
| 46 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 47 |
+
train_dataset.X,
|
| 48 |
+
y_train,
|
| 49 |
+
train_dataset.w,
|
| 50 |
+
train_dataset.ids,
|
| 51 |
+
tasks=pdbbind_tasks)
|
| 52 |
+
|
| 53 |
+
y_test = test_dataset.y
|
| 54 |
+
y_test *= -1 * 2.479 / 4.184
|
| 55 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 56 |
+
test_dataset.X,
|
| 57 |
+
y_test,
|
| 58 |
+
test_dataset.w,
|
| 59 |
+
test_dataset.ids,
|
| 60 |
+
tasks=pdbbind_tasks)
|
| 61 |
+
|
| 62 |
+
at = [6, 7., 8., 9., 11., 12., 15., 16., 17., 20., 25., 30., 35., 53.]
|
| 63 |
+
radial = [[
|
| 64 |
+
1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5,
|
| 65 |
+
9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0
|
| 66 |
+
], [0.0, 4.0, 8.0], [0.4]]
|
| 67 |
+
#radial = [[12.0], [0.0, 4.0, 8.0], [0.4]]
|
| 68 |
+
rp = create_symmetry_parameters(radial)
|
| 69 |
+
layer_sizes = [32, 32, 16]
|
| 70 |
+
weight_init_stddevs = [
|
| 71 |
+
1 / np.sqrt(layer_sizes[0]), 1 / np.sqrt(layer_sizes[1]),
|
| 72 |
+
1 / np.sqrt(layer_sizes[2])
|
| 73 |
+
]
|
| 74 |
+
dropouts = [0.3, 0.3, 0.05]
|
| 75 |
+
penalty_type = "l2"
|
| 76 |
+
penalty = 0.
|
| 77 |
+
model = TensorflowFragmentRegressor(
|
| 78 |
+
len(pdbbind_tasks),
|
| 79 |
+
rp,
|
| 80 |
+
at,
|
| 81 |
+
frag1_num_atoms,
|
| 82 |
+
frag2_num_atoms,
|
| 83 |
+
complex_num_atoms,
|
| 84 |
+
max_num_neighbors,
|
| 85 |
+
logdir=model_dir,
|
| 86 |
+
layer_sizes=layer_sizes,
|
| 87 |
+
weight_init_stddevs=weight_init_stddevs,
|
| 88 |
+
bias_init_consts=[0., 0., 0.],
|
| 89 |
+
penalty=penalty,
|
| 90 |
+
penalty_type=penalty_type,
|
| 91 |
+
dropouts=dropouts,
|
| 92 |
+
learning_rate=0.002,
|
| 93 |
+
momentum=0.8,
|
| 94 |
+
optimizer="adam",
|
| 95 |
+
batch_size=64,
|
| 96 |
+
conv_layers=1,
|
| 97 |
+
boxsize=None,
|
| 98 |
+
verbose=True,
|
| 99 |
+
seed=seed)
|
| 100 |
+
model.fit(train_dataset, nb_epoch=100)
|
| 101 |
+
metric = [
|
| 102 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression"),
|
| 103 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression")
|
| 104 |
+
]
|
| 105 |
+
train_evaluator = dc.utils.evaluate.Evaluator(model, train_dataset,
|
| 106 |
+
transformers)
|
| 107 |
+
train_scores = train_evaluator.compute_model_performance(
|
| 108 |
+
metric,
|
| 109 |
+
csv_out="train_predict_ac_scaffold.csv",
|
| 110 |
+
stats_out="train_stats_ac_scaffold.csv")
|
| 111 |
+
print("Train scores")
|
| 112 |
+
print(train_scores)
|
| 113 |
+
test_evaluator = dc.utils.evaluate.Evaluator(model, test_dataset, transformers)
|
| 114 |
+
test_scores = test_evaluator.compute_model_performance(
|
| 115 |
+
metric,
|
| 116 |
+
csv_out="test_predict_ac_scaffold.csv",
|
| 117 |
+
stats_out="test_stats_ac_scaffold.csv")
|
| 118 |
+
print("Test scores")
|
| 119 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/core/opt_stratified.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
__author__ = "Joseph Gomes"
|
| 6 |
+
__copyright__ = "Copyright 2017, Stanford University"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import deepchem as dc
|
| 12 |
+
import numpy as np
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
|
| 15 |
+
sys.path.append("../../models")
|
| 16 |
+
from atomicnet_ops import create_symmetry_parameters
|
| 17 |
+
from atomicnet import TensorflowFragmentRegressor
|
| 18 |
+
|
| 19 |
+
seed = 123
|
| 20 |
+
np.random.seed(seed)
|
| 21 |
+
tf.set_random_seed(seed)
|
| 22 |
+
|
| 23 |
+
base_dir = os.getcwd()
|
| 24 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 25 |
+
train_dir = os.path.join(data_dir, "stratified_train")
|
| 26 |
+
test_dir = os.path.join(data_dir, "stratified_test")
|
| 27 |
+
model_dir = os.path.join(base_dir, "stratified_model")
|
| 28 |
+
|
| 29 |
+
frag1_num_atoms = 70
|
| 30 |
+
frag2_num_atoms = 634
|
| 31 |
+
complex_num_atoms = 701
|
| 32 |
+
max_num_neighbors = 12
|
| 33 |
+
neighbor_cutoff = 12.0
|
| 34 |
+
|
| 35 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 36 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 37 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 38 |
+
transformers = []
|
| 39 |
+
#transformers = [dc.trans.NormalizationTransformer(transform_y=True, dataset=train_dataset)]
|
| 40 |
+
#for transformer in transformers:
|
| 41 |
+
# train_dataset = transformer.transform(train_dataset)
|
| 42 |
+
# test_dataset = transformer.transform(test_dataset)
|
| 43 |
+
|
| 44 |
+
y_train = train_dataset.y
|
| 45 |
+
y_train *= -1 * 2.479 / 4.184
|
| 46 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 47 |
+
train_dataset.X,
|
| 48 |
+
y_train,
|
| 49 |
+
train_dataset.w,
|
| 50 |
+
train_dataset.ids,
|
| 51 |
+
tasks=pdbbind_tasks)
|
| 52 |
+
|
| 53 |
+
y_test = test_dataset.y
|
| 54 |
+
y_test *= -1 * 2.479 / 4.184
|
| 55 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 56 |
+
test_dataset.X,
|
| 57 |
+
y_test,
|
| 58 |
+
test_dataset.w,
|
| 59 |
+
test_dataset.ids,
|
| 60 |
+
tasks=pdbbind_tasks)
|
| 61 |
+
|
| 62 |
+
at = [6, 7., 8., 9., 11., 12., 15., 16., 17., 20., 25., 30., 35., 53.]
|
| 63 |
+
radial = [[
|
| 64 |
+
1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5,
|
| 65 |
+
9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0
|
| 66 |
+
], [0.0, 4.0, 8.0], [0.4]]
|
| 67 |
+
#radial = [[12.0], [0.0, 4.0, 8.0], [0.4]]
|
| 68 |
+
rp = create_symmetry_parameters(radial)
|
| 69 |
+
layer_sizes = [32, 32, 16]
|
| 70 |
+
weight_init_stddevs = [
|
| 71 |
+
1 / np.sqrt(layer_sizes[0]), 1 / np.sqrt(layer_sizes[1]),
|
| 72 |
+
1 / np.sqrt(layer_sizes[2])
|
| 73 |
+
]
|
| 74 |
+
dropouts = [0.3, 0.3, 0.05]
|
| 75 |
+
penalty_type = "l2"
|
| 76 |
+
penalty = 0.
|
| 77 |
+
model = TensorflowFragmentRegressor(
|
| 78 |
+
len(pdbbind_tasks),
|
| 79 |
+
rp,
|
| 80 |
+
at,
|
| 81 |
+
frag1_num_atoms,
|
| 82 |
+
frag2_num_atoms,
|
| 83 |
+
complex_num_atoms,
|
| 84 |
+
max_num_neighbors,
|
| 85 |
+
logdir=model_dir,
|
| 86 |
+
layer_sizes=layer_sizes,
|
| 87 |
+
weight_init_stddevs=weight_init_stddevs,
|
| 88 |
+
bias_init_consts=[0., 0., 0.],
|
| 89 |
+
penalty=penalty,
|
| 90 |
+
penalty_type=penalty_type,
|
| 91 |
+
dropouts=dropouts,
|
| 92 |
+
learning_rate=0.002,
|
| 93 |
+
momentum=0.8,
|
| 94 |
+
optimizer="adam",
|
| 95 |
+
batch_size=64,
|
| 96 |
+
conv_layers=1,
|
| 97 |
+
boxsize=None,
|
| 98 |
+
verbose=True,
|
| 99 |
+
seed=seed)
|
| 100 |
+
model.fit(train_dataset, nb_epoch=100)
|
| 101 |
+
metric = [
|
| 102 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression"),
|
| 103 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression")
|
| 104 |
+
]
|
| 105 |
+
train_evaluator = dc.utils.evaluate.Evaluator(model, train_dataset,
|
| 106 |
+
transformers)
|
| 107 |
+
train_scores = train_evaluator.compute_model_performance(
|
| 108 |
+
metric,
|
| 109 |
+
csv_out="train_predict_ac_stratified.csv",
|
| 110 |
+
stats_out="train_stats_ac_stratified.csv")
|
| 111 |
+
print("Train scores")
|
| 112 |
+
print(train_scores)
|
| 113 |
+
test_evaluator = dc.utils.evaluate.Evaluator(model, test_dataset, transformers)
|
| 114 |
+
test_scores = test_evaluator.compute_model_performance(
|
| 115 |
+
metric,
|
| 116 |
+
csv_out="test_predict_ac_stratified.csv",
|
| 117 |
+
stats_out="test_stats_ac_stratified.csv")
|
| 118 |
+
print("Test scores")
|
| 119 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/core/opt_temporal.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
__author__ = "Joseph Gomes"
|
| 6 |
+
__copyright__ = "Copyright 2017, Stanford University"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import deepchem as dc
|
| 12 |
+
import numpy as np
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
|
| 15 |
+
sys.path.append("../../models")
|
| 16 |
+
from atomicnet_ops import create_symmetry_parameters
|
| 17 |
+
from atomicnet import TensorflowFragmentRegressor
|
| 18 |
+
|
| 19 |
+
seed = 123
|
| 20 |
+
np.random.seed(seed)
|
| 21 |
+
tf.set_random_seed(seed)
|
| 22 |
+
|
| 23 |
+
base_dir = os.getcwd()
|
| 24 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 25 |
+
train_dir = os.path.join(data_dir, "temporal_train")
|
| 26 |
+
test_dir = os.path.join(data_dir, "temporal_test")
|
| 27 |
+
model_dir = os.path.join(base_dir, "temporal_model")
|
| 28 |
+
|
| 29 |
+
frag1_num_atoms = 70
|
| 30 |
+
frag2_num_atoms = 634
|
| 31 |
+
complex_num_atoms = 701
|
| 32 |
+
max_num_neighbors = 12
|
| 33 |
+
neighbor_cutoff = 12.0
|
| 34 |
+
|
| 35 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 36 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 37 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 38 |
+
transformers = []
|
| 39 |
+
#transformers = [dc.trans.NormalizationTransformer(transform_y=True, dataset=train_dataset)]
|
| 40 |
+
#for transformer in transformers:
|
| 41 |
+
# train_dataset = transformer.transform(train_dataset)
|
| 42 |
+
# test_dataset = transformer.transform(test_dataset)
|
| 43 |
+
|
| 44 |
+
y_train = train_dataset.y
|
| 45 |
+
y_train *= -1 * 2.479 / 4.184
|
| 46 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 47 |
+
train_dataset.X,
|
| 48 |
+
y_train,
|
| 49 |
+
train_dataset.w,
|
| 50 |
+
train_dataset.ids,
|
| 51 |
+
tasks=pdbbind_tasks)
|
| 52 |
+
|
| 53 |
+
y_test = test_dataset.y
|
| 54 |
+
y_test *= -1 * 2.479 / 4.184
|
| 55 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 56 |
+
test_dataset.X,
|
| 57 |
+
y_test,
|
| 58 |
+
test_dataset.w,
|
| 59 |
+
test_dataset.ids,
|
| 60 |
+
tasks=pdbbind_tasks)
|
| 61 |
+
|
| 62 |
+
at = [6, 7., 8., 9., 11., 12., 15., 16., 17., 20., 25., 30., 35., 53.]
|
| 63 |
+
radial = [[
|
| 64 |
+
1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5,
|
| 65 |
+
9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0
|
| 66 |
+
], [0.0, 4.0, 8.0], [0.4]]
|
| 67 |
+
#radial = [[12.0], [0.0, 4.0, 8.0], [0.4]]
|
| 68 |
+
rp = create_symmetry_parameters(radial)
|
| 69 |
+
layer_sizes = [32, 32, 16]
|
| 70 |
+
weight_init_stddevs = [
|
| 71 |
+
1 / np.sqrt(layer_sizes[0]), 1 / np.sqrt(layer_sizes[1]),
|
| 72 |
+
1 / np.sqrt(layer_sizes[2])
|
| 73 |
+
]
|
| 74 |
+
dropouts = [0.3, 0.3, 0.05]
|
| 75 |
+
penalty_type = "l2"
|
| 76 |
+
penalty = 0.
|
| 77 |
+
model = TensorflowFragmentRegressor(
|
| 78 |
+
len(pdbbind_tasks),
|
| 79 |
+
rp,
|
| 80 |
+
at,
|
| 81 |
+
frag1_num_atoms,
|
| 82 |
+
frag2_num_atoms,
|
| 83 |
+
complex_num_atoms,
|
| 84 |
+
max_num_neighbors,
|
| 85 |
+
logdir=model_dir,
|
| 86 |
+
layer_sizes=layer_sizes,
|
| 87 |
+
weight_init_stddevs=weight_init_stddevs,
|
| 88 |
+
bias_init_consts=[0., 0., 0.],
|
| 89 |
+
penalty=penalty,
|
| 90 |
+
penalty_type=penalty_type,
|
| 91 |
+
dropouts=dropouts,
|
| 92 |
+
learning_rate=0.002,
|
| 93 |
+
momentum=0.8,
|
| 94 |
+
optimizer="adam",
|
| 95 |
+
batch_size=64,
|
| 96 |
+
conv_layers=1,
|
| 97 |
+
boxsize=None,
|
| 98 |
+
verbose=True,
|
| 99 |
+
seed=seed)
|
| 100 |
+
model.fit(train_dataset, nb_epoch=100)
|
| 101 |
+
metric = [
|
| 102 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression"),
|
| 103 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression")
|
| 104 |
+
]
|
| 105 |
+
train_evaluator = dc.utils.evaluate.Evaluator(model, train_dataset,
|
| 106 |
+
transformers)
|
| 107 |
+
train_scores = train_evaluator.compute_model_performance(
|
| 108 |
+
metric,
|
| 109 |
+
csv_out="train_predict_ac_temporal.csv",
|
| 110 |
+
stats_out="train_stats_ac_temporal.csv")
|
| 111 |
+
print("Train scores")
|
| 112 |
+
print(train_scores)
|
| 113 |
+
test_evaluator = dc.utils.evaluate.Evaluator(model, test_dataset, transformers)
|
| 114 |
+
test_scores = test_evaluator.compute_model_performance(
|
| 115 |
+
metric,
|
| 116 |
+
csv_out="test_predict_ac_temporal.csv",
|
| 117 |
+
stats_out="test_stats_ac_temporal.csv")
|
| 118 |
+
print("Test scores")
|
| 119 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/core/tensor_graph_hyper_param_eval.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import deepchem as dc
|
| 8 |
+
import json
|
| 9 |
+
import numpy as np
|
| 10 |
+
import tensorflow as tf
|
| 11 |
+
from deepchem.models.atomic_conv import atomic_conv_model
|
| 12 |
+
|
| 13 |
+
sys.path.append("../../models")
|
| 14 |
+
from deepchem.models.tensorgraph.layers import Layer, Feature, Label, L2Loss, AtomicConvolution, Transpose, Dense
|
| 15 |
+
from deepchem.models import TensorGraph
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
import tensorflow as tf
|
| 19 |
+
import itertools
|
| 20 |
+
import time
|
| 21 |
+
|
| 22 |
+
seed = 123
|
| 23 |
+
np.random.seed(seed)
|
| 24 |
+
tf.set_random_seed(seed)
|
| 25 |
+
|
| 26 |
+
base_dir = os.getcwd()
|
| 27 |
+
|
| 28 |
+
batch_size = 24
|
| 29 |
+
splits = ["random", "scaffold", "stratified", "temporal"]
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def params():
|
| 33 |
+
d2 = {
|
| 34 |
+
"name":
|
| 35 |
+
"hyper5",
|
| 36 |
+
"radial": [[
|
| 37 |
+
1.5, 2.5, 3.5, 4.5, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0,
|
| 38 |
+
10.5
|
| 39 |
+
], [0.0, 2.0, 4.0], [0.05]],
|
| 40 |
+
"layer_sizes": [32, 16, 8],
|
| 41 |
+
"learning_rate":
|
| 42 |
+
0.001,
|
| 43 |
+
"epochs":
|
| 44 |
+
10,
|
| 45 |
+
}
|
| 46 |
+
yield d2
|
| 47 |
+
d2 = {
|
| 48 |
+
"name":
|
| 49 |
+
"hyper6",
|
| 50 |
+
"radial": [[
|
| 51 |
+
1.5, 2.0, 2.5, 3.5, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0,
|
| 52 |
+
9.5, 10.0, 10.5
|
| 53 |
+
], [0.0, 2.0, 4.0], [0.1]],
|
| 54 |
+
"layer_sizes": [32, 32, 16],
|
| 55 |
+
"learning_rate":
|
| 56 |
+
0.001,
|
| 57 |
+
"epochs":
|
| 58 |
+
10,
|
| 59 |
+
}
|
| 60 |
+
yield d2
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
metric = [
|
| 64 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression"),
|
| 65 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression")
|
| 66 |
+
]
|
| 67 |
+
for split in splits:
|
| 68 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 69 |
+
train_dir = os.path.join(data_dir, "%s_train" % split)
|
| 70 |
+
test_dir = os.path.join(data_dir, "%s_test" % split)
|
| 71 |
+
|
| 72 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 73 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 74 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 75 |
+
transformers = []
|
| 76 |
+
|
| 77 |
+
y_train = train_dataset.y
|
| 78 |
+
y_train *= -1 * 2.479 / 4.184
|
| 79 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 80 |
+
train_dataset.X,
|
| 81 |
+
y_train,
|
| 82 |
+
train_dataset.w,
|
| 83 |
+
train_dataset.ids,
|
| 84 |
+
tasks=pdbbind_tasks)
|
| 85 |
+
|
| 86 |
+
y_test = test_dataset.y
|
| 87 |
+
y_test *= -1 * 2.479 / 4.184
|
| 88 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 89 |
+
test_dataset.X,
|
| 90 |
+
y_test,
|
| 91 |
+
test_dataset.w,
|
| 92 |
+
test_dataset.ids,
|
| 93 |
+
tasks=pdbbind_tasks)
|
| 94 |
+
for param in params():
|
| 95 |
+
num_epochs = param['epochs']
|
| 96 |
+
del param['epochs']
|
| 97 |
+
name = param['name']
|
| 98 |
+
del param['name']
|
| 99 |
+
|
| 100 |
+
tg, feed_dict_generator, label = atomic_conv_model(**param)
|
| 101 |
+
tg.fit_generator(
|
| 102 |
+
feed_dict_generator(train_dataset, batch_size, epochs=num_epochs))
|
| 103 |
+
|
| 104 |
+
test_evaluator = dc.utils.evaluate.GeneratorEvaluator(
|
| 105 |
+
tg, feed_dict_generator(test_dataset, batch_size), transformers,
|
| 106 |
+
[label])
|
| 107 |
+
test_scores = test_evaluator.compute_model_performance(metric)
|
| 108 |
+
param.update(test_scores)
|
| 109 |
+
param['epochs'] = num_epochs
|
| 110 |
+
param['split'] = split
|
| 111 |
+
param['name'] = name
|
| 112 |
+
print("Results")
|
| 113 |
+
print(param)
|
| 114 |
+
with open('hyper_evaluation.txt', 'a') as fout:
|
| 115 |
+
fout.write(json.dumps(param))
|
| 116 |
+
fout.write("\n")
|
deepchem/source/contrib/atomicconv/acnn/core/tensor_graph_hyper_param_search.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import deepchem as dc
|
| 8 |
+
import json
|
| 9 |
+
import numpy as np
|
| 10 |
+
import tensorflow as tf
|
| 11 |
+
from deepchem.models.atomic_conv import atomic_conv_model
|
| 12 |
+
|
| 13 |
+
sys.path.append("../../models")
|
| 14 |
+
from deepchem.models.tensorgraph.layers import Layer, Feature, Label, L2Loss, AtomicConvolution, Transpose, Dense
|
| 15 |
+
from deepchem.models import TensorGraph
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
import tensorflow as tf
|
| 19 |
+
import itertools
|
| 20 |
+
import time
|
| 21 |
+
|
| 22 |
+
seed = 123
|
| 23 |
+
np.random.seed(seed)
|
| 24 |
+
tf.set_random_seed(seed)
|
| 25 |
+
|
| 26 |
+
base_dir = os.getcwd()
|
| 27 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 28 |
+
train_dir = os.path.join(data_dir, "scaffold_train")
|
| 29 |
+
test_dir = os.path.join(data_dir, "scaffold_test")
|
| 30 |
+
|
| 31 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 32 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 33 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 34 |
+
transformers = []
|
| 35 |
+
|
| 36 |
+
y_train = train_dataset.y
|
| 37 |
+
y_train *= -1 * 2.479 / 4.184
|
| 38 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 39 |
+
train_dataset.X,
|
| 40 |
+
y_train,
|
| 41 |
+
train_dataset.w,
|
| 42 |
+
train_dataset.ids,
|
| 43 |
+
tasks=pdbbind_tasks)
|
| 44 |
+
|
| 45 |
+
y_test = test_dataset.y
|
| 46 |
+
y_test *= -1 * 2.479 / 4.184
|
| 47 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 48 |
+
test_dataset.X,
|
| 49 |
+
y_test,
|
| 50 |
+
test_dataset.w,
|
| 51 |
+
test_dataset.ids,
|
| 52 |
+
tasks=pdbbind_tasks)
|
| 53 |
+
|
| 54 |
+
batch_size = 24
|
| 55 |
+
radial1 = [
|
| 56 |
+
[1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5],
|
| 57 |
+
[
|
| 58 |
+
1.5, 2.5, 3.5, 4.5, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0,
|
| 59 |
+
10.5
|
| 60 |
+
],
|
| 61 |
+
]
|
| 62 |
+
radial2 = [
|
| 63 |
+
[0.0, 2.0, 4.0],
|
| 64 |
+
[0.0, 1.0, 2.0],
|
| 65 |
+
[0.0, 1.5, 3.0],
|
| 66 |
+
]
|
| 67 |
+
radial3 = [
|
| 68 |
+
[0.075],
|
| 69 |
+
]
|
| 70 |
+
layer_sizes = [
|
| 71 |
+
[64, 32, 16],
|
| 72 |
+
[32, 16, 8],
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
learning_rates = [
|
| 76 |
+
0.001,
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
epochs = [10]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def params():
|
| 83 |
+
for values in itertools.product(radial1, radial2, radial3, layer_sizes,
|
| 84 |
+
learning_rates, epochs):
|
| 85 |
+
d = {
|
| 86 |
+
"frag1_num_atoms": 140,
|
| 87 |
+
"frag2_num_atoms": 821,
|
| 88 |
+
"complex_num_atoms": 908,
|
| 89 |
+
"radial": [values[0], values[1], values[2]],
|
| 90 |
+
"layer_sizes": values[3],
|
| 91 |
+
"learning_rate": values[4],
|
| 92 |
+
"epochs": values[5]
|
| 93 |
+
}
|
| 94 |
+
yield d
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
metric = [
|
| 98 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression"),
|
| 99 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression")
|
| 100 |
+
]
|
| 101 |
+
for param in params():
|
| 102 |
+
num_epochs = param['epochs']
|
| 103 |
+
del param['epochs']
|
| 104 |
+
tg, feed_dict_generator, label = atomic_conv_model(**param)
|
| 105 |
+
tg.fit_generator(
|
| 106 |
+
feed_dict_generator(train_dataset, batch_size, epochs=num_epochs))
|
| 107 |
+
|
| 108 |
+
test_evaluator = dc.utils.evaluate.GeneratorEvaluator(
|
| 109 |
+
tg, feed_dict_generator(test_dataset, batch_size), transformers, [label])
|
| 110 |
+
test_scores = test_evaluator.compute_model_performance(metric)
|
| 111 |
+
param.update(test_scores)
|
| 112 |
+
param['epochs'] = num_epochs
|
| 113 |
+
print("Results")
|
| 114 |
+
print(param)
|
| 115 |
+
with open('hyper_results.txt', 'a') as fout:
|
| 116 |
+
fout.write(json.dumps(param))
|
| 117 |
+
fout.write("\n")
|
deepchem/source/contrib/atomicconv/acnn/refined/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
deepchem/source/contrib/atomicconv/acnn/refined/get_acnn_refined.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
echo "Pulling featurized and split ACNN datasets from deepchem"
|
| 2 |
+
wget http://deepchem.io.s3-website-us-west-1.amazonaws.com/featurized_datasets/acnn_refined.tar.gz
|
| 3 |
+
echo "Extracting ACNN datasets"
|
| 4 |
+
tar -zxvf acnn_refined.tar.gz
|
deepchem/source/contrib/atomicconv/acnn/refined/opt_random.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
__author__ = "Joseph Gomes"
|
| 6 |
+
__copyright__ = "Copyright 2017, Stanford University"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import deepchem as dc
|
| 12 |
+
import numpy as np
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
|
| 15 |
+
sys.path.append("../../models")
|
| 16 |
+
from atomicnet_ops import create_symmetry_parameters
|
| 17 |
+
from atomicnet import TensorflowFragmentRegressor
|
| 18 |
+
|
| 19 |
+
# Set random seeds
|
| 20 |
+
seed = 123
|
| 21 |
+
np.random.seed(seed)
|
| 22 |
+
tf.set_random_seed(seed)
|
| 23 |
+
|
| 24 |
+
# Setup directories
|
| 25 |
+
base_dir = os.getcwd()
|
| 26 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 27 |
+
train_dir = os.path.join(data_dir, "random_train")
|
| 28 |
+
test_dir = os.path.join(data_dir, "random_test")
|
| 29 |
+
model_dir = os.path.join(base_dir, "random_model")
|
| 30 |
+
|
| 31 |
+
# Model constants
|
| 32 |
+
frag1_num_atoms = 153
|
| 33 |
+
frag2_num_atoms = 1119
|
| 34 |
+
complex_num_atoms = 1254
|
| 35 |
+
max_num_neighbors = 12
|
| 36 |
+
neighbor_cutoff = 12.0
|
| 37 |
+
|
| 38 |
+
# Load and transform datasets
|
| 39 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 40 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 41 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 42 |
+
|
| 43 |
+
transformers = []
|
| 44 |
+
# convert -logKi to dG = +RTlogKi [kJ/mol]
|
| 45 |
+
y_train = train_dataset.y
|
| 46 |
+
y_train *= -1 * 2.479 / 4.184
|
| 47 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 48 |
+
train_dataset.X,
|
| 49 |
+
y_train,
|
| 50 |
+
train_dataset.w,
|
| 51 |
+
train_dataset.ids,
|
| 52 |
+
tasks=pdbbind_tasks)
|
| 53 |
+
y_test = test_dataset.y
|
| 54 |
+
y_test *= -1 * 2.479 / 4.184
|
| 55 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 56 |
+
test_dataset.X,
|
| 57 |
+
y_test,
|
| 58 |
+
test_dataset.w,
|
| 59 |
+
test_dataset.ids,
|
| 60 |
+
tasks=pdbbind_tasks)
|
| 61 |
+
|
| 62 |
+
# Atomic convolution variables
|
| 63 |
+
# at = atomic numbers (atom types)
|
| 64 |
+
# radial basis function parameters [cutoff, mean, width]
|
| 65 |
+
at = [
|
| 66 |
+
1., 6., 7., 8., 9., 11., 12., 15., 16., 17., 19., 20., 25., 26., 27., 28.,
|
| 67 |
+
29., 30., 34., 35., 38., 48., 53., 55., 80.
|
| 68 |
+
]
|
| 69 |
+
radial = [[1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0],
|
| 70 |
+
[0.0], [0.4]]
|
| 71 |
+
rp = create_symmetry_parameters(radial)
|
| 72 |
+
|
| 73 |
+
# Model hyperparameters
|
| 74 |
+
layer_sizes = [32, 32, 16]
|
| 75 |
+
weight_init_stddevs = [1 / np.sqrt(x) for x in layer_sizes]
|
| 76 |
+
bias_init_consts = [0. for x in layer_sizes]
|
| 77 |
+
penalty_type = "l2"
|
| 78 |
+
penalty = 0.
|
| 79 |
+
dropouts = [0.25, 0.25, 0.]
|
| 80 |
+
learning_rate = 0.001
|
| 81 |
+
momentum = 0.8
|
| 82 |
+
batch_size = 24
|
| 83 |
+
|
| 84 |
+
# Initialize model
|
| 85 |
+
model = TensorflowFragmentRegressor(
|
| 86 |
+
len(pdbbind_tasks),
|
| 87 |
+
rp,
|
| 88 |
+
at,
|
| 89 |
+
frag1_num_atoms,
|
| 90 |
+
frag2_num_atoms,
|
| 91 |
+
complex_num_atoms,
|
| 92 |
+
max_num_neighbors,
|
| 93 |
+
logdir=model_dir,
|
| 94 |
+
layer_sizes=layer_sizes,
|
| 95 |
+
weight_init_stddevs=weight_init_stddevs,
|
| 96 |
+
bias_init_consts=bias_init_consts,
|
| 97 |
+
penalty=penalty,
|
| 98 |
+
penalty_type=penalty_type,
|
| 99 |
+
dropouts=dropouts,
|
| 100 |
+
learning_rate=learning_rate,
|
| 101 |
+
momentum=momentum,
|
| 102 |
+
optimizer="adam",
|
| 103 |
+
batch_size=batch_size,
|
| 104 |
+
conv_layers=1,
|
| 105 |
+
boxsize=None,
|
| 106 |
+
verbose=True,
|
| 107 |
+
seed=seed)
|
| 108 |
+
|
| 109 |
+
# Fit model
|
| 110 |
+
model.fit(train_dataset, nb_epoch=10)
|
| 111 |
+
|
| 112 |
+
# Evaluate model
|
| 113 |
+
metric = [
|
| 114 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression"),
|
| 115 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression")
|
| 116 |
+
]
|
| 117 |
+
train_evaluator = dc.utils.evaluate.Evaluator(model, train_dataset,
|
| 118 |
+
transformers)
|
| 119 |
+
train_scores = train_evaluator.compute_model_performance(metric)
|
| 120 |
+
print("Train scores")
|
| 121 |
+
print(train_scores)
|
| 122 |
+
test_evaluator = dc.utils.evaluate.Evaluator(model, test_dataset, transformers)
|
| 123 |
+
test_scores = test_evaluator.compute_model_performance(metric)
|
| 124 |
+
print("Test scores")
|
| 125 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/refined/opt_scaffold.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
__author__ = "Joseph Gomes"
|
| 6 |
+
__copyright__ = "Copyright 2017, Stanford University"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import deepchem as dc
|
| 12 |
+
import numpy as np
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
|
| 15 |
+
sys.path.append("../../models")
|
| 16 |
+
from atomicnet_ops import create_symmetry_parameters
|
| 17 |
+
from atomicnet import TensorflowFragmentRegressor
|
| 18 |
+
|
| 19 |
+
# Set random seeds
|
| 20 |
+
seed = 123
|
| 21 |
+
np.random.seed(seed)
|
| 22 |
+
tf.set_random_seed(seed)
|
| 23 |
+
|
| 24 |
+
# Setup directories
|
| 25 |
+
base_dir = os.getcwd()
|
| 26 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 27 |
+
train_dir = os.path.join(data_dir, "scaffold_train")
|
| 28 |
+
test_dir = os.path.join(data_dir, "scaffold_test")
|
| 29 |
+
model_dir = os.path.join(base_dir, "scaffold_model")
|
| 30 |
+
|
| 31 |
+
# Model constants
|
| 32 |
+
frag1_num_atoms = 153
|
| 33 |
+
frag2_num_atoms = 1119
|
| 34 |
+
complex_num_atoms = 1254
|
| 35 |
+
max_num_neighbors = 12
|
| 36 |
+
neighbor_cutoff = 12.0
|
| 37 |
+
|
| 38 |
+
# Load and transform datasets
|
| 39 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 40 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 41 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 42 |
+
|
| 43 |
+
transformers = []
|
| 44 |
+
# convert -logKi to dG = +RTlogKi [kJ/mol]
|
| 45 |
+
y_train = train_dataset.y
|
| 46 |
+
y_train *= -1 * 2.479 / 4.184
|
| 47 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 48 |
+
train_dataset.X,
|
| 49 |
+
y_train,
|
| 50 |
+
train_dataset.w,
|
| 51 |
+
train_dataset.ids,
|
| 52 |
+
tasks=pdbbind_tasks)
|
| 53 |
+
y_test = test_dataset.y
|
| 54 |
+
y_test *= -1 * 2.479 / 4.184
|
| 55 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 56 |
+
test_dataset.X,
|
| 57 |
+
y_test,
|
| 58 |
+
test_dataset.w,
|
| 59 |
+
test_dataset.ids,
|
| 60 |
+
tasks=pdbbind_tasks)
|
| 61 |
+
|
| 62 |
+
# Atomic convolution variables
|
| 63 |
+
# at = atomic numbers (atom types)
|
| 64 |
+
# radial basis function parameters [cutoff, mean, width]
|
| 65 |
+
at = [
|
| 66 |
+
1., 6., 7., 8., 9., 11., 12., 15., 16., 17., 19., 20., 25., 26., 27., 28.,
|
| 67 |
+
29., 30., 34., 35., 38., 48., 53., 55., 80.
|
| 68 |
+
]
|
| 69 |
+
radial = [[1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0],
|
| 70 |
+
[0.0], [0.4]]
|
| 71 |
+
rp = create_symmetry_parameters(radial)
|
| 72 |
+
|
| 73 |
+
# Model hyperparameters
|
| 74 |
+
layer_sizes = [32, 32, 16]
|
| 75 |
+
weight_init_stddevs = [1 / np.sqrt(x) for x in layer_sizes]
|
| 76 |
+
bias_init_consts = [0. for x in layer_sizes]
|
| 77 |
+
penalty_type = "l2"
|
| 78 |
+
penalty = 0.
|
| 79 |
+
dropouts = [0.25, 0.25, 0.]
|
| 80 |
+
learning_rate = 0.001
|
| 81 |
+
momentum = 0.8
|
| 82 |
+
batch_size = 24
|
| 83 |
+
|
| 84 |
+
# Initialize model
|
| 85 |
+
model = TensorflowFragmentRegressor(
|
| 86 |
+
len(pdbbind_tasks),
|
| 87 |
+
rp,
|
| 88 |
+
at,
|
| 89 |
+
frag1_num_atoms,
|
| 90 |
+
frag2_num_atoms,
|
| 91 |
+
complex_num_atoms,
|
| 92 |
+
max_num_neighbors,
|
| 93 |
+
logdir=model_dir,
|
| 94 |
+
layer_sizes=layer_sizes,
|
| 95 |
+
weight_init_stddevs=weight_init_stddevs,
|
| 96 |
+
bias_init_consts=bias_init_consts,
|
| 97 |
+
penalty=penalty,
|
| 98 |
+
penalty_type=penalty_type,
|
| 99 |
+
dropouts=dropouts,
|
| 100 |
+
learning_rate=learning_rate,
|
| 101 |
+
momentum=momentum,
|
| 102 |
+
optimizer="adam",
|
| 103 |
+
batch_size=batch_size,
|
| 104 |
+
conv_layers=1,
|
| 105 |
+
boxsize=None,
|
| 106 |
+
verbose=True,
|
| 107 |
+
seed=seed)
|
| 108 |
+
|
| 109 |
+
# Fit model
|
| 110 |
+
model.fit(train_dataset, nb_epoch=10)
|
| 111 |
+
|
| 112 |
+
# Evaluate model
|
| 113 |
+
metric = [
|
| 114 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression"),
|
| 115 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression")
|
| 116 |
+
]
|
| 117 |
+
train_evaluator = dc.utils.evaluate.Evaluator(model, train_dataset,
|
| 118 |
+
transformers)
|
| 119 |
+
train_scores = train_evaluator.compute_model_performance(metric)
|
| 120 |
+
print("Train scores")
|
| 121 |
+
print(train_scores)
|
| 122 |
+
test_evaluator = dc.utils.evaluate.Evaluator(model, test_dataset, transformers)
|
| 123 |
+
test_scores = test_evaluator.compute_model_performance(metric)
|
| 124 |
+
print("Test scores")
|
| 125 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/refined/opt_stratified.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
__author__ = "Joseph Gomes"
|
| 6 |
+
__copyright__ = "Copyright 2017, Stanford University"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import deepchem as dc
|
| 12 |
+
import numpy as np
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
|
| 15 |
+
sys.path.append("../../models")
|
| 16 |
+
from atomicnet_ops import create_symmetry_parameters
|
| 17 |
+
from atomicnet import TensorflowFragmentRegressor
|
| 18 |
+
|
| 19 |
+
# Set random seeds
|
| 20 |
+
seed = 123
|
| 21 |
+
np.random.seed(seed)
|
| 22 |
+
tf.set_random_seed(seed)
|
| 23 |
+
|
| 24 |
+
# Setup directories
|
| 25 |
+
base_dir = os.getcwd()
|
| 26 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 27 |
+
train_dir = os.path.join(data_dir, "stratified_train")
|
| 28 |
+
test_dir = os.path.join(data_dir, "stratified_test")
|
| 29 |
+
model_dir = os.path.join(base_dir, "stratified_model")
|
| 30 |
+
|
| 31 |
+
# Model constants
|
| 32 |
+
frag1_num_atoms = 153
|
| 33 |
+
frag2_num_atoms = 1119
|
| 34 |
+
complex_num_atoms = 1254
|
| 35 |
+
max_num_neighbors = 12
|
| 36 |
+
neighbor_cutoff = 12.0
|
| 37 |
+
|
| 38 |
+
# Load and transform datasets
|
| 39 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 40 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 41 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 42 |
+
|
| 43 |
+
transformers = []
|
| 44 |
+
# convert -logKi to dG = +RTlogKi [kJ/mol]
|
| 45 |
+
y_train = train_dataset.y
|
| 46 |
+
y_train *= -1 * 2.479 / 4.184
|
| 47 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 48 |
+
train_dataset.X,
|
| 49 |
+
y_train,
|
| 50 |
+
train_dataset.w,
|
| 51 |
+
train_dataset.ids,
|
| 52 |
+
tasks=pdbbind_tasks)
|
| 53 |
+
y_test = test_dataset.y
|
| 54 |
+
y_test *= -1 * 2.479 / 4.184
|
| 55 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 56 |
+
test_dataset.X,
|
| 57 |
+
y_test,
|
| 58 |
+
test_dataset.w,
|
| 59 |
+
test_dataset.ids,
|
| 60 |
+
tasks=pdbbind_tasks)
|
| 61 |
+
|
| 62 |
+
# Atomic convolution variables
|
| 63 |
+
# at = atomic numbers (atom types)
|
| 64 |
+
# radial basis function parameters [cutoff, mean, width]
|
| 65 |
+
at = [
|
| 66 |
+
1., 6., 7., 8., 9., 11., 12., 15., 16., 17., 19., 20., 25., 26., 27., 28.,
|
| 67 |
+
29., 30., 34., 35., 38., 48., 53., 55., 80.
|
| 68 |
+
]
|
| 69 |
+
radial = [[1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0],
|
| 70 |
+
[0.0], [0.4]]
|
| 71 |
+
rp = create_symmetry_parameters(radial)
|
| 72 |
+
|
| 73 |
+
# Model hyperparameters
|
| 74 |
+
layer_sizes = [32, 32, 16]
|
| 75 |
+
weight_init_stddevs = [1 / np.sqrt(x) for x in layer_sizes]
|
| 76 |
+
bias_init_consts = [0. for x in layer_sizes]
|
| 77 |
+
penalty_type = "l2"
|
| 78 |
+
penalty = 0.
|
| 79 |
+
dropouts = [0.25, 0.25, 0.]
|
| 80 |
+
learning_rate = 0.001
|
| 81 |
+
momentum = 0.8
|
| 82 |
+
batch_size = 24
|
| 83 |
+
|
| 84 |
+
# Initialize model
|
| 85 |
+
model = TensorflowFragmentRegressor(
|
| 86 |
+
len(pdbbind_tasks),
|
| 87 |
+
rp,
|
| 88 |
+
at,
|
| 89 |
+
frag1_num_atoms,
|
| 90 |
+
frag2_num_atoms,
|
| 91 |
+
complex_num_atoms,
|
| 92 |
+
max_num_neighbors,
|
| 93 |
+
logdir=model_dir,
|
| 94 |
+
layer_sizes=layer_sizes,
|
| 95 |
+
weight_init_stddevs=weight_init_stddevs,
|
| 96 |
+
bias_init_consts=bias_init_consts,
|
| 97 |
+
penalty=penalty,
|
| 98 |
+
penalty_type=penalty_type,
|
| 99 |
+
dropouts=dropouts,
|
| 100 |
+
learning_rate=learning_rate,
|
| 101 |
+
momentum=momentum,
|
| 102 |
+
optimizer="adam",
|
| 103 |
+
batch_size=batch_size,
|
| 104 |
+
conv_layers=1,
|
| 105 |
+
boxsize=None,
|
| 106 |
+
verbose=True,
|
| 107 |
+
seed=seed)
|
| 108 |
+
|
| 109 |
+
# Fit model
|
| 110 |
+
model.fit(train_dataset, nb_epoch=10)
|
| 111 |
+
|
| 112 |
+
# Evaluate model
|
| 113 |
+
metric = [
|
| 114 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression"),
|
| 115 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression")
|
| 116 |
+
]
|
| 117 |
+
train_evaluator = dc.utils.evaluate.Evaluator(model, train_dataset,
|
| 118 |
+
transformers)
|
| 119 |
+
train_scores = train_evaluator.compute_model_performance(metric)
|
| 120 |
+
print("Train scores")
|
| 121 |
+
print(train_scores)
|
| 122 |
+
test_evaluator = dc.utils.evaluate.Evaluator(model, test_dataset, transformers)
|
| 123 |
+
test_scores = test_evaluator.compute_model_performance(metric)
|
| 124 |
+
print("Test scores")
|
| 125 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/refined/opt_temporal.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
__author__ = "Joseph Gomes"
|
| 6 |
+
__copyright__ = "Copyright 2017, Stanford University"
|
| 7 |
+
__license__ = "MIT"
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import deepchem as dc
|
| 12 |
+
import numpy as np
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
|
| 15 |
+
sys.path.append("../../models")
|
| 16 |
+
from atomicnet_ops import create_symmetry_parameters
|
| 17 |
+
from atomicnet import TensorflowFragmentRegressor
|
| 18 |
+
|
| 19 |
+
# Set random seeds
|
| 20 |
+
seed = 123
|
| 21 |
+
np.random.seed(seed)
|
| 22 |
+
tf.set_random_seed(seed)
|
| 23 |
+
|
| 24 |
+
# Setup directories
|
| 25 |
+
base_dir = os.getcwd()
|
| 26 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 27 |
+
train_dir = os.path.join(data_dir, "temporal_train")
|
| 28 |
+
test_dir = os.path.join(data_dir, "temporal_test")
|
| 29 |
+
model_dir = os.path.join(base_dir, "temporal_model")
|
| 30 |
+
|
| 31 |
+
# Model constants
|
| 32 |
+
frag1_num_atoms = 153
|
| 33 |
+
frag2_num_atoms = 1119
|
| 34 |
+
complex_num_atoms = 1254
|
| 35 |
+
max_num_neighbors = 12
|
| 36 |
+
neighbor_cutoff = 12.0
|
| 37 |
+
|
| 38 |
+
# Load and transform datasets
|
| 39 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 40 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 41 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 42 |
+
|
| 43 |
+
transformers = []
|
| 44 |
+
# convert -logKi to dG = +RTlogKi [kJ/mol]
|
| 45 |
+
y_train = train_dataset.y
|
| 46 |
+
y_train *= -1 * 2.479 / 4.184
|
| 47 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 48 |
+
train_dataset.X,
|
| 49 |
+
y_train,
|
| 50 |
+
train_dataset.w,
|
| 51 |
+
train_dataset.ids,
|
| 52 |
+
tasks=pdbbind_tasks)
|
| 53 |
+
y_test = test_dataset.y
|
| 54 |
+
y_test *= -1 * 2.479 / 4.184
|
| 55 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 56 |
+
test_dataset.X,
|
| 57 |
+
y_test,
|
| 58 |
+
test_dataset.w,
|
| 59 |
+
test_dataset.ids,
|
| 60 |
+
tasks=pdbbind_tasks)
|
| 61 |
+
|
| 62 |
+
# Atomic convolution variables
|
| 63 |
+
# at = atomic numbers (atom types)
|
| 64 |
+
# radial basis function parameters [cutoff, mean, width]
|
| 65 |
+
at = [
|
| 66 |
+
1., 6., 7., 8., 9., 11., 12., 15., 16., 17., 19., 20., 25., 26., 27., 28.,
|
| 67 |
+
29., 30., 34., 35., 38., 48., 53., 55., 80.
|
| 68 |
+
]
|
| 69 |
+
radial = [[1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0],
|
| 70 |
+
[0.0], [0.4]]
|
| 71 |
+
rp = create_symmetry_parameters(radial)
|
| 72 |
+
|
| 73 |
+
# Model hyperparameters
|
| 74 |
+
layer_sizes = [32, 32, 16]
|
| 75 |
+
weight_init_stddevs = [1 / np.sqrt(x) for x in layer_sizes]
|
| 76 |
+
bias_init_consts = [0. for x in layer_sizes]
|
| 77 |
+
penalty_type = "l2"
|
| 78 |
+
penalty = 0.
|
| 79 |
+
dropouts = [0.25, 0.25, 0.]
|
| 80 |
+
learning_rate = 0.001
|
| 81 |
+
momentum = 0.8
|
| 82 |
+
batch_size = 24
|
| 83 |
+
|
| 84 |
+
# Initialize model
|
| 85 |
+
model = TensorflowFragmentRegressor(
|
| 86 |
+
len(pdbbind_tasks),
|
| 87 |
+
rp,
|
| 88 |
+
at,
|
| 89 |
+
frag1_num_atoms,
|
| 90 |
+
frag2_num_atoms,
|
| 91 |
+
complex_num_atoms,
|
| 92 |
+
max_num_neighbors,
|
| 93 |
+
logdir=model_dir,
|
| 94 |
+
layer_sizes=layer_sizes,
|
| 95 |
+
weight_init_stddevs=weight_init_stddevs,
|
| 96 |
+
bias_init_consts=bias_init_consts,
|
| 97 |
+
penalty=penalty,
|
| 98 |
+
penalty_type=penalty_type,
|
| 99 |
+
dropouts=dropouts,
|
| 100 |
+
learning_rate=learning_rate,
|
| 101 |
+
momentum=momentum,
|
| 102 |
+
optimizer="adam",
|
| 103 |
+
batch_size=batch_size,
|
| 104 |
+
conv_layers=1,
|
| 105 |
+
boxsize=None,
|
| 106 |
+
verbose=True,
|
| 107 |
+
seed=seed)
|
| 108 |
+
|
| 109 |
+
# Fit model
|
| 110 |
+
model.fit(train_dataset, nb_epoch=10)
|
| 111 |
+
|
| 112 |
+
# Evaluate model
|
| 113 |
+
metric = [
|
| 114 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression"),
|
| 115 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression")
|
| 116 |
+
]
|
| 117 |
+
train_evaluator = dc.utils.evaluate.Evaluator(model, train_dataset,
|
| 118 |
+
transformers)
|
| 119 |
+
train_scores = train_evaluator.compute_model_performance(metric)
|
| 120 |
+
print("Train scores")
|
| 121 |
+
print(train_scores)
|
| 122 |
+
test_evaluator = dc.utils.evaluate.Evaluator(model, test_dataset, transformers)
|
| 123 |
+
test_scores = test_evaluator.compute_model_performance(metric)
|
| 124 |
+
print("Test scores")
|
| 125 |
+
print(test_scores)
|
deepchem/source/contrib/atomicconv/acnn/refined/tensor_graph_hyper_param_eval.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import print_function
|
| 2 |
+
from __future__ import division
|
| 3 |
+
from __future__ import unicode_literals
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import deepchem as dc
|
| 8 |
+
import json
|
| 9 |
+
import numpy as np
|
| 10 |
+
import tensorflow as tf
|
| 11 |
+
from deepchem.models.atomic_conv import atomic_conv_model
|
| 12 |
+
|
| 13 |
+
sys.path.append("../../models")
|
| 14 |
+
from deepchem.models.tensorgraph.layers import Layer, Feature, Label, L2Loss, AtomicConvolution, Transpose, Dense
|
| 15 |
+
from deepchem.models import TensorGraph
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
import tensorflow as tf
|
| 19 |
+
import itertools
|
| 20 |
+
import time
|
| 21 |
+
|
| 22 |
+
seed = 123
|
| 23 |
+
np.random.seed(seed)
|
| 24 |
+
tf.set_random_seed(seed)
|
| 25 |
+
|
| 26 |
+
base_dir = os.getcwd()
|
| 27 |
+
|
| 28 |
+
batch_size = 24
|
| 29 |
+
splits = ["random", "stratified", "index", "scaffold"]
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def params():
|
| 33 |
+
d2 = {
|
| 34 |
+
"name":
|
| 35 |
+
"hyper5",
|
| 36 |
+
"radial": [[
|
| 37 |
+
1.5, 2.5, 3.5, 4.5, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0,
|
| 38 |
+
10.5
|
| 39 |
+
], [0.0, 2.0, 4.0], [0.05]],
|
| 40 |
+
"layer_sizes": [32, 16, 8],
|
| 41 |
+
"learning_rate":
|
| 42 |
+
0.001,
|
| 43 |
+
"epochs":
|
| 44 |
+
10,
|
| 45 |
+
"frag1_num_atoms":
|
| 46 |
+
71,
|
| 47 |
+
"frag2_num_atoms":
|
| 48 |
+
912,
|
| 49 |
+
"complex_num_atoms":
|
| 50 |
+
982,
|
| 51 |
+
}
|
| 52 |
+
yield d2
|
| 53 |
+
d2 = {
|
| 54 |
+
"name":
|
| 55 |
+
"original",
|
| 56 |
+
"radial": [[
|
| 57 |
+
1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0,
|
| 58 |
+
8.5, 9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0
|
| 59 |
+
], [0.0, 4.0, 8.0], [0.4]],
|
| 60 |
+
"layer_sizes": [32, 32, 16],
|
| 61 |
+
"learning_rate":
|
| 62 |
+
0.001,
|
| 63 |
+
"epochs":
|
| 64 |
+
10,
|
| 65 |
+
"frag1_num_atoms":
|
| 66 |
+
71,
|
| 67 |
+
"frag2_num_atoms":
|
| 68 |
+
912,
|
| 69 |
+
"complex_num_atoms":
|
| 70 |
+
982,
|
| 71 |
+
}
|
| 72 |
+
yield d2
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
metric = [
|
| 76 |
+
dc.metrics.Metric(dc.metrics.mean_absolute_error, mode="regression"),
|
| 77 |
+
dc.metrics.Metric(dc.metrics.pearson_r2_score, mode="regression")
|
| 78 |
+
]
|
| 79 |
+
for split in splits:
|
| 80 |
+
data_dir = os.path.join(base_dir, "datasets")
|
| 81 |
+
train_dir = os.path.join(data_dir, "%s_train" % split)
|
| 82 |
+
valid_dir = os.path.join(data_dir, "%s_valid" % split)
|
| 83 |
+
test_dir = os.path.join(data_dir, "%s_test" % split)
|
| 84 |
+
|
| 85 |
+
train_dataset = dc.data.DiskDataset(train_dir)
|
| 86 |
+
valid_dataset = dc.data.DiskDataset(train_dir)
|
| 87 |
+
test_dataset = dc.data.DiskDataset(test_dir)
|
| 88 |
+
pdbbind_tasks = ["-logKd/Ki"]
|
| 89 |
+
transformers = []
|
| 90 |
+
|
| 91 |
+
y_train = train_dataset.y
|
| 92 |
+
y_train *= -1 * 2.479 / 4.184
|
| 93 |
+
train_dataset = dc.data.DiskDataset.from_numpy(
|
| 94 |
+
train_dataset.X,
|
| 95 |
+
y_train,
|
| 96 |
+
train_dataset.w,
|
| 97 |
+
train_dataset.ids,
|
| 98 |
+
tasks=pdbbind_tasks)
|
| 99 |
+
|
| 100 |
+
y_test = test_dataset.y
|
| 101 |
+
y_test *= -1 * 2.479 / 4.184
|
| 102 |
+
test_dataset = dc.data.DiskDataset.from_numpy(
|
| 103 |
+
test_dataset.X,
|
| 104 |
+
y_test,
|
| 105 |
+
test_dataset.w,
|
| 106 |
+
test_dataset.ids,
|
| 107 |
+
tasks=pdbbind_tasks)
|
| 108 |
+
for param in params():
|
| 109 |
+
num_epochs = param['epochs']
|
| 110 |
+
del param['epochs']
|
| 111 |
+
name = param['name']
|
| 112 |
+
del param['name']
|
| 113 |
+
|
| 114 |
+
tg, feed_dict_generator, label = atomic_conv_model(**param)
|
| 115 |
+
for i in range(2):
|
| 116 |
+
tg.fit_generator(
|
| 117 |
+
feed_dict_generator(train_dataset, batch_size, epochs=num_epochs))
|
| 118 |
+
|
| 119 |
+
valid_evaluator = dc.utils.evaluate.GeneratorEvaluator(
|
| 120 |
+
tg,
|
| 121 |
+
feed_dict_generator(valid_dataset, batch_size), transformers, [label])
|
| 122 |
+
valid_scores = valid_evaluator.compute_model_performance(metric)
|
| 123 |
+
valid_scores = {"%s_valid" % k: v for k, v in valid_scores.items()}
|
| 124 |
+
param.update(valid_scores)
|
| 125 |
+
# test_evaluator = dc.utils.evaluate.GeneratorEvaluator(
|
| 126 |
+
# tg, feed_dict_generator(test_dataset, batch_size), transformers, [label])
|
| 127 |
+
# test_scores = test_evaluator.compute_model_performance(metric)
|
| 128 |
+
# test_scores = {"%s_test" % k: v for k, v in test_scores.items()}
|
| 129 |
+
# param.update(test_scores)
|
| 130 |
+
param['epochs'] = num_epochs * (i + 1)
|
| 131 |
+
param['split'] = split
|
| 132 |
+
param['name'] = name
|
| 133 |
+
print("Results")
|
| 134 |
+
print(param)
|
| 135 |
+
with open('hyper_evaluation.txt', 'a') as fout:
|
| 136 |
+
fout.write(json.dumps(param))
|
| 137 |
+
fout.write("\n")
|