proef 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- proef/__init__.py +25 -0
- proef/acquisition.py +244 -0
- proef/ad.py +159 -0
- proef/adapters/__init__.py +0 -0
- proef/adapters/admet.py +196 -0
- proef/adapters/bio/__init__.py +0 -0
- proef/adapters/bio/rdkit_ops.py +52 -0
- proef/adapters/bio/safety_rules.json +146 -0
- proef/adapters/bio/seq_alerts.py +79 -0
- proef/adapters/bio/structure_score.py +85 -0
- proef/adapters/bio/tox_alerts.py +99 -0
- proef/adapters/data/__init__.py +0 -0
- proef/adapters/data/admet.py +62 -0
- proef/adapters/data/chembl.py +110 -0
- proef/adapters/data/frozen/admet/MANIFEST.json +48 -0
- proef/adapters/data/frozen/admet/bbb_martins/test.csv +407 -0
- proef/adapters/data/frozen/admet/bbb_martins/train_val.csv +1625 -0
- proef/adapters/data/frozen/admet/caco2_wang/test.csv +183 -0
- proef/adapters/data/frozen/admet/caco2_wang/train_val.csv +729 -0
- proef/adapters/data/frozen/admet/hia_hou/test.csv +118 -0
- proef/adapters/data/frozen/admet/hia_hou/train_val.csv +462 -0
- proef/adapters/data/moleculenet.py +60 -0
- proef/adapters/databases/__init__.py +0 -0
- proef/adapters/databases/chembl_gates.py +121 -0
- proef/adapters/databases/chembl_lookup.py +35 -0
- proef/adapters/databases/open_targets.py +102 -0
- proef/adapters/databases/pubmed.py +94 -0
- proef/adapters/devices/__init__.py +0 -0
- proef/adapters/devices/ezo_ph.py +251 -0
- proef/adapters/devices/hcs_microscope.py +143 -0
- proef/adapters/devices/lcms.py +123 -0
- proef/adapters/devices/scheduler.py +84 -0
- proef/adapters/devices/sila2.py +134 -0
- proef/adapters/genomics/alphagenome.py +146 -0
- proef/adapters/lab/__init__.py +0 -0
- proef/adapters/lab/bioprocess.py +32 -0
- proef/adapters/lab/devices.py +170 -0
- proef/adapters/lab/imaging.py +226 -0
- proef/adapters/lab/mhs_driver.py +124 -0
- proef/adapters/lab/opentrons.py +222 -0
- proef/adapters/lab/ot2_sim.py +174 -0
- proef/adapters/lab/plate_reader_share.py +108 -0
- proef/adapters/lab/protein_design.py +199 -0
- proef/adapters/lab/recording.py +119 -0
- proef/adapters/lab/replay.py +107 -0
- proef/adapters/lab/simulator.py +282 -0
- proef/adapters/lab/synthesis.py +92 -0
- proef/adapters/models/__init__.py +0 -0
- proef/adapters/models/anthropic_provider.py +157 -0
- proef/adapters/models/assayloop_ranker.py +67 -0
- proef/adapters/models/from_env.py +93 -0
- proef/adapters/models/gp_policy.py +93 -0
- proef/adapters/models/gp_policy_gp.py +36 -0
- proef/adapters/models/llm_policy.py +187 -0
- proef/adapters/models/openai_compat.py +150 -0
- proef/adapters/models/sklearn_policy.py +65 -0
- proef/adapters/retrosynthesis.py +247 -0
- proef/adapters/sandbox/__init__.py +20 -0
- proef/adapters/sandbox/agentenv.py +145 -0
- proef/adapters/sandbox/docker.py +217 -0
- proef/adapters/sandbox/local.py +164 -0
- proef/adapters/sandbox/opensandbox.py +122 -0
- proef/adapters/store/__init__.py +0 -0
- proef/adapters/store/sqlite.py +207 -0
- proef/adaptive.py +108 -0
- proef/advisory.py +76 -0
- proef/analysis_profiles/__init__.py +8 -0
- proef/analysis_profiles/measurements.py +266 -0
- proef/analysis_profiles/plate_assay.py +316 -0
- proef/analysis_report.py +195 -0
- proef/analysis_store.py +183 -0
- proef/anchor.py +154 -0
- proef/api/app.py +107 -0
- proef/api/launch.py +170 -0
- proef/api/v1/__init__.py +29 -0
- proef/api/v1/analyses.py +367 -0
- proef/api/v1/campaigns.py +802 -0
- proef/api/v1/deps.py +10 -0
- proef/api/v1/evals.py +16 -0
- proef/api/v1/evidence.py +132 -0
- proef/api/v1/governance.py +35 -0
- proef/api/v1/inbox.py +119 -0
- proef/api/v1/lab.py +110 -0
- proef/api/v1/pauses.py +77 -0
- proef/api/v1/programs.py +397 -0
- proef/api/v1/results.py +147 -0
- proef/api/v1/schemas.py +932 -0
- proef/api/v1/system.py +79 -0
- proef/api/v1/trees.py +216 -0
- proef/api/wizard_sessions.py +253 -0
- proef/approvals.py +102 -0
- proef/assays/__init__.py +15 -0
- proef/assays/dls.py +114 -0
- proef/assays/dsf.py +81 -0
- proef/assays/elisa.py +58 -0
- proef/assays/properties.py +65 -0
- proef/assays/simulate.py +157 -0
- proef/audit.py +152 -0
- proef/autoloop.py +1620 -0
- proef/benchmark.py +442 -0
- proef/campaign_fsm.py +151 -0
- proef/citations.py +141 -0
- proef/cli.py +1249 -0
- proef/connect.py +74 -0
- proef/core/__init__.py +0 -0
- proef/core/contracts/__init__.py +35 -0
- proef/core/contracts/analysis.py +100 -0
- proef/core/contracts/models.py +395 -0
- proef/core/device_card.py +125 -0
- proef/core/hypothesis.py +720 -0
- proef/core/interfaces.py +164 -0
- proef/core/registry.py +123 -0
- proef/core/safety.py +324 -0
- proef/core/workflow.py +159 -0
- proef/critic.py +62 -0
- proef/demo.py +164 -0
- proef/derivation.py +128 -0
- proef/diary.py +301 -0
- proef/eln.py +87 -0
- proef/evals/__init__.py +1 -0
- proef/evals/hallucination.py +86 -0
- proef/evals/harness.py +358 -0
- proef/evals/orchestration.py +254 -0
- proef/evals/tasks.py +1010 -0
- proef/evals/toolcalls.py +425 -0
- proef/experiment.py +172 -0
- proef/experiment_analysis.py +114 -0
- proef/experiments/__init__.py +0 -0
- proef/experiments/grounding_exp.py +689 -0
- proef/figures.py +218 -0
- proef/fitting.py +309 -0
- proef/fixtures.py +140 -0
- proef/flywheel.py +125 -0
- proef/followup.py +126 -0
- proef/governance.py +290 -0
- proef/groundedness.py +361 -0
- proef/grounding.py +202 -0
- proef/hypothesis_agent.py +369 -0
- proef/ingest.py +157 -0
- proef/instruments.json +173 -0
- proef/interpret.py +95 -0
- proef/kinetic.py +102 -0
- proef/labread/__init__.py +45 -0
- proef/labread/analysis.py +428 -0
- proef/labread/common.py +153 -0
- proef/labread/formats.py +190 -0
- proef/labread/layout.py +168 -0
- proef/labread/pubchem.py +179 -0
- proef/labselect.py +431 -0
- proef/materials.py +140 -0
- proef/mcp_instrument.py +396 -0
- proef/mcp_server.py +283 -0
- proef/modality.py +111 -0
- proef/model_guard.py +245 -0
- proef/output_blocks.py +183 -0
- proef/paths.py +32 -0
- proef/physfail.py +55 -0
- proef/plan.py +160 -0
- proef/plots.py +123 -0
- proef/predictors.py +217 -0
- proef/probes.py +79 -0
- proef/problem_tree.py +581 -0
- proef/program.py +308 -0
- proef/protocol_design.py +42 -0
- proef/proxy.py +78 -0
- proef/readiness.py +259 -0
- proef/reliability.py +49 -0
- proef/report.py +117 -0
- proef/reproduce.py +310 -0
- proef/reviewer.py +254 -0
- proef/sandbox_session.py +247 -0
- proef/sandboxd.py +109 -0
- proef/scaffold.py +195 -0
- proef/series.py +327 -0
- proef/skills.py +203 -0
- proef/sweep.py +83 -0
- proef/taste.py +177 -0
- proef/templates/confirmatory-followup.json +34 -0
- proef/templates/dose-response-screen.json +39 -0
- proef/templates/sar-exploration.json +38 -0
- proef/templates.py +124 -0
- proef/toolkit.py +433 -0
- proef/toolloop.py +133 -0
- proef/tools.py +441 -0
- proef/tpp.py +185 -0
- proef/views/__init__.py +14 -0
- proef/views/counts.py +102 -0
- proef/views/experiment.py +154 -0
- proef/views/ids.py +49 -0
- proef/views/narrative.py +294 -0
- proef/views/pipeline.py +370 -0
- proef/vision.py +165 -0
- proef/watch.py +790 -0
- proef/wizard_chain.py +25 -0
- proef/wizard_store.py +373 -0
- proef-0.2.0.dist-info/METADATA +662 -0
- proef-0.2.0.dist-info/RECORD +200 -0
- proef-0.2.0.dist-info/WHEEL +4 -0
- proef-0.2.0.dist-info/entry_points.txt +14 -0
- proef-0.2.0.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "safety-rules-v1",
|
|
3
|
+
"sources": [
|
|
4
|
+
"Murakami/Benigni-style curated toxicophores",
|
|
5
|
+
"NSAB Select Agent & Toxin list (text families)"
|
|
6
|
+
],
|
|
7
|
+
"alerts": [
|
|
8
|
+
{
|
|
9
|
+
"name": "aromatic_nitro",
|
|
10
|
+
"smarts": "c[N+](=O)[O-]",
|
|
11
|
+
"severity": "hard",
|
|
12
|
+
"note": "mutagenicity (DNA adducts after reduction)"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "aromatic_amine_vic",
|
|
16
|
+
"smarts": "Nc1ccc(N)cc1",
|
|
17
|
+
"severity": "hard",
|
|
18
|
+
"note": "p-phenylenediamine: methemoglobinemia/redox"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "hydroquinone",
|
|
22
|
+
"smarts": "Oc1ccc(O)cc1",
|
|
23
|
+
"severity": "medium",
|
|
24
|
+
"note": "redox cycling / quinone formation"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "quinone",
|
|
28
|
+
"smarts": "O=C1C=CC(=O)C=C1",
|
|
29
|
+
"severity": "hard",
|
|
30
|
+
"note": "redox cycling, Michael acceptor"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "hydrazine",
|
|
34
|
+
"smarts": "[NX3][NX3]",
|
|
35
|
+
"severity": "hard",
|
|
36
|
+
"note": "mutagenicity"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "azo",
|
|
40
|
+
"smarts": "N=N",
|
|
41
|
+
"severity": "hard",
|
|
42
|
+
"note": "azo: reductive cleavage to aromatic amines"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "acyl_halide",
|
|
46
|
+
"smarts": "C(=O)Cl",
|
|
47
|
+
"severity": "hard",
|
|
48
|
+
"note": "acylating agent"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "sulfonyl_halide",
|
|
52
|
+
"smarts": "S(=O)(=O)Cl",
|
|
53
|
+
"severity": "hard",
|
|
54
|
+
"note": "sulfonylating agent"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "isocyanate",
|
|
58
|
+
"smarts": "N=C=O",
|
|
59
|
+
"severity": "hard",
|
|
60
|
+
"note": "protein haptenation"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "azide",
|
|
64
|
+
"smarts": "[N-][N+]#N",
|
|
65
|
+
"severity": "hard",
|
|
66
|
+
"note": "nitrene precursor / explosive handle"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "aziridine",
|
|
70
|
+
"smarts": "C1NC1",
|
|
71
|
+
"severity": "hard",
|
|
72
|
+
"note": "direct alkylator"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "mustard_like",
|
|
76
|
+
"smarts": "Cl[CX4][CX4][NX3]",
|
|
77
|
+
"severity": "hard",
|
|
78
|
+
"note": "nitrogen-mustard motif: alkylator"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"name": "alpha_haloketone",
|
|
82
|
+
"smarts": "O=C[CH2]Cl",
|
|
83
|
+
"severity": "hard",
|
|
84
|
+
"note": "reactive alkylator"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "epoxide",
|
|
88
|
+
"smarts": "C1OC1",
|
|
89
|
+
"severity": "medium",
|
|
90
|
+
"note": "alkylating strain electrophile"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "michael_acceptor",
|
|
94
|
+
"smarts": "C=C[CHX3][CX3]=[OX1]",
|
|
95
|
+
"severity": "medium",
|
|
96
|
+
"note": "Michael acceptor (enone/enal/enoate)"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "acrylamide",
|
|
100
|
+
"smarts": "C=CC(=O)N",
|
|
101
|
+
"severity": "medium",
|
|
102
|
+
"note": "soft thiol electrophile"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "vinyl_sulfonamide",
|
|
106
|
+
"smarts": "C=CS(=O)(=O)",
|
|
107
|
+
"severity": "medium",
|
|
108
|
+
"note": "covalent warhead (BTK-style intent)"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "aldehyde_aromatic",
|
|
112
|
+
"smarts": "[cH][CX3H](=O)",
|
|
113
|
+
"severity": "medium",
|
|
114
|
+
"note": "Schiff-base hapten"
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"select_agents": [
|
|
118
|
+
"variola",
|
|
119
|
+
"smallpox",
|
|
120
|
+
"bacillus anthracis",
|
|
121
|
+
"anthrax",
|
|
122
|
+
"yersinia pestis",
|
|
123
|
+
"plague",
|
|
124
|
+
"francisella tularensis",
|
|
125
|
+
"tularensis",
|
|
126
|
+
"burkholderia mallei",
|
|
127
|
+
"burkholderia pseudomallei",
|
|
128
|
+
"clostridium botulinum",
|
|
129
|
+
"botulinum toxin",
|
|
130
|
+
"ebola",
|
|
131
|
+
"marburg",
|
|
132
|
+
"lassa",
|
|
133
|
+
"nipah",
|
|
134
|
+
"hendra",
|
|
135
|
+
"rickettsia prowazekii",
|
|
136
|
+
"coxiella burnetii",
|
|
137
|
+
"coccidioides immitis",
|
|
138
|
+
"avian influenza",
|
|
139
|
+
"h5n1",
|
|
140
|
+
"ricin",
|
|
141
|
+
"ricinus communis",
|
|
142
|
+
"staphylococcal enterotoxin b",
|
|
143
|
+
"severe acute respiratory syndrome coronavirus 2",
|
|
144
|
+
"sars-coronavirus"
|
|
145
|
+
]
|
|
146
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Sequence safety screening — the biologics side of the safety gate.
|
|
2
|
+
|
|
3
|
+
Small molecules are screened structurally (toxicophore SMARTS on SMILES).
|
|
4
|
+
Biologics are sequences: proteins, mRNAs, DNA. There is no SMARTS for a
|
|
5
|
+
protein, so the screen is deliberately honest about what it can check:
|
|
6
|
+
|
|
7
|
+
1. FORMAT — the sequence must be a valid polymer (amino-acid or
|
|
8
|
+
nucleotide alphabet, sane length). Garbage dressed as a sequence is
|
|
9
|
+
refused, not silently waved through.
|
|
10
|
+
2. NAME SCREEN — every protocol string is screened against the same
|
|
11
|
+
regulated-agent list as chemistry (DurcTargetRule covers this at
|
|
12
|
+
protocol level; here we also screen per-sequence description/organism
|
|
13
|
+
metadata, because a sample named "botulinum construct" must not hide
|
|
14
|
+
inside an innocuous-looking sequence).
|
|
15
|
+
3. LENGTH CEILING — configurable; constructs beyond it require the same
|
|
16
|
+
human review as BSL-2 chemistry. Default 10 kb.
|
|
17
|
+
|
|
18
|
+
Versioned like the chemistry rules: refusals cite the screen version.
|
|
19
|
+
What this screen does NOT claim: it does not predict toxicity or
|
|
20
|
+
immunogenicity from sequence — that is Test-phase work for real assays.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import re
|
|
25
|
+
|
|
26
|
+
SEQ_SCREEN_VERSION = "seq-screen-v1"
|
|
27
|
+
|
|
28
|
+
AA_ALPHABET = set("ACDEFGHIKLMNPQRSTVWYBXZUO-")
|
|
29
|
+
NT_ALPHABET = set("ACGTUN-")
|
|
30
|
+
|
|
31
|
+
_RESTRICTED_NAME_FRAGMENTS = [
|
|
32
|
+
"botulinum", "ricin", "abrin", "saxitoxin", "tetrodotoxin",
|
|
33
|
+
"variola", "ebolavirus", "marburg", "yersinia pestis",
|
|
34
|
+
"francisella", "bacillus anthracis", "clos#tridium",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def screen_sequence(sequence: str, description: str = "",
|
|
39
|
+
max_length: int = 10_000) -> list[str]:
|
|
40
|
+
"""Returns a list of refusal reasons; empty list = passes."""
|
|
41
|
+
reasons: list[str] = []
|
|
42
|
+
seq = (sequence or "").strip().upper().replace(" ", "")
|
|
43
|
+
if not seq:
|
|
44
|
+
return ["empty sequence"]
|
|
45
|
+
if len(seq) > max_length:
|
|
46
|
+
reasons.append(f"construct length {len(seq)} nt/aa exceeds the "
|
|
47
|
+
f"{max_length} ceiling — human review required")
|
|
48
|
+
looks_nt = set(seq) <= NT_ALPHABET
|
|
49
|
+
looks_aa = set(seq) <= AA_ALPHABET
|
|
50
|
+
if not (looks_nt or looks_aa):
|
|
51
|
+
bad = sorted(set(seq) - (AA_ALPHABET | NT_ALPHABET))[:5]
|
|
52
|
+
reasons.append("invalid polymer alphabet (unexpected characters: "
|
|
53
|
+
+ ", ".join(bad) + ")")
|
|
54
|
+
blob = f"{description} {seq[:60]}".lower()
|
|
55
|
+
for frag in _RESTRICTED_NAME_FRAGMENTS:
|
|
56
|
+
if re.search(re.escape(frag.replace("#", "")), blob):
|
|
57
|
+
reasons.append(f"names a regulated toxin/organism "
|
|
58
|
+
f"('{frag}') — dual-use review required")
|
|
59
|
+
break
|
|
60
|
+
return reasons
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class SequenceScreenRule:
|
|
64
|
+
"""Safety-gate rule for biologic samples: any sample carrying
|
|
65
|
+
metadata['sequence'] is screened before the lab sees it."""
|
|
66
|
+
|
|
67
|
+
name = "sequence_screen"
|
|
68
|
+
|
|
69
|
+
def check(self, protocol) -> str | None:
|
|
70
|
+
for s in protocol.samples:
|
|
71
|
+
seq = (s.metadata or {}).get("sequence")
|
|
72
|
+
if not seq:
|
|
73
|
+
continue
|
|
74
|
+
reasons = screen_sequence(
|
|
75
|
+
str(seq), str((s.metadata or {}).get("description", "")))
|
|
76
|
+
if reasons:
|
|
77
|
+
return (f"sequence screen ({SEQ_SCREEN_VERSION}) refused "
|
|
78
|
+
f"sample '{s.sample_id}': " + "; ".join(reasons))
|
|
79
|
+
return None
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Structure-model scoring — the biologics Design-phase BioTool.
|
|
2
|
+
|
|
3
|
+
Scores a protein sequence for predicted structural stability and model
|
|
4
|
+
confidence. Two backends:
|
|
5
|
+
|
|
6
|
+
- "stub": deterministic offline score (hash-seeded) — for tests and the
|
|
7
|
+
virtual lab. Honest label: it is a placeholder number, not a real
|
|
8
|
+
prediction; `model_version` says so.
|
|
9
|
+
- "http": POSTs the sequence to a configured endpoint (e.g. an ESMFold/
|
|
10
|
+
ESM-compatible server). The endpoint and key come from options —
|
|
11
|
+
no keys in code.
|
|
12
|
+
|
|
13
|
+
Implements the BioTool protocol (capability c.fm.predict_structure).
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import hashlib
|
|
18
|
+
import json
|
|
19
|
+
import random
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from proef.core.contracts.models import (ToolInvocation, ToolName,
|
|
23
|
+
ToolResult)
|
|
24
|
+
|
|
25
|
+
STUB_VERSION = "structure-stub-v1"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class StructureScorer:
|
|
29
|
+
name = "structure-scorer"
|
|
30
|
+
capabilities = (ToolName.fm_predict_structure,)
|
|
31
|
+
|
|
32
|
+
def __init__(self, backend: str = "stub",
|
|
33
|
+
endpoint: str | None = None, api_key: str | None = None):
|
|
34
|
+
if backend not in ("stub", "http"):
|
|
35
|
+
raise ValueError(f"unknown backend {backend!r}")
|
|
36
|
+
if backend == "http" and not endpoint:
|
|
37
|
+
raise ValueError("http backend requires an endpoint")
|
|
38
|
+
self.backend = backend
|
|
39
|
+
self.endpoint = endpoint
|
|
40
|
+
self.api_key = api_key
|
|
41
|
+
|
|
42
|
+
def score(self, sequence: str) -> dict[str, Any]:
|
|
43
|
+
seq = (sequence or "").strip().upper()
|
|
44
|
+
if self.backend == "stub":
|
|
45
|
+
seed = int(hashlib.sha256(seq.encode()).hexdigest()[:8], 16)
|
|
46
|
+
rng = random.Random(seed)
|
|
47
|
+
confidence = round(55 + rng.random() * 40, 1) # pLDDT-ish
|
|
48
|
+
stability = round(rng.random(), 3)
|
|
49
|
+
return {"stability_score": stability,
|
|
50
|
+
"confidence": confidence,
|
|
51
|
+
"aggregation_risk": round(1 - stability, 3),
|
|
52
|
+
"backend": STUB_VERSION}
|
|
53
|
+
# http backend: minimal JSON POST, tolerant of ESM-like servers
|
|
54
|
+
import urllib.request
|
|
55
|
+
req = urllib.request.Request(
|
|
56
|
+
self.endpoint,
|
|
57
|
+
data=json.dumps({"sequence": seq}).encode(),
|
|
58
|
+
headers={"Content-Type": "application/json",
|
|
59
|
+
**({"Authorization": f"Bearer {self.api_key}"}
|
|
60
|
+
if self.api_key else {})})
|
|
61
|
+
with urllib.request.urlopen(req, timeout=60) as resp:
|
|
62
|
+
out = json.loads(resp.read())
|
|
63
|
+
return {"stability_score": float(out.get("stability_score",
|
|
64
|
+
out.get("mean_plddt", 0))
|
|
65
|
+
/ 100 if "mean_plddt" in out
|
|
66
|
+
else out.get("stability_score", 0)),
|
|
67
|
+
"confidence": float(out.get("confidence",
|
|
68
|
+
out.get("mean_plddt", 0))),
|
|
69
|
+
"aggregation_risk": float(out.get("aggregation_risk", 0)),
|
|
70
|
+
"backend": f"http:{self.endpoint}"}
|
|
71
|
+
|
|
72
|
+
# ---- BioTool protocol -------------------------------------------------
|
|
73
|
+
def invoke(self, invocation: ToolInvocation) -> ToolResult:
|
|
74
|
+
seq = invocation.args.get("sequence", "")
|
|
75
|
+
try:
|
|
76
|
+
out = self.score(str(seq))
|
|
77
|
+
return ToolResult(envelope=invocation.envelope,
|
|
78
|
+
invocation_id=invocation.invocation_id,
|
|
79
|
+
status="succeeded", output=out,
|
|
80
|
+
model_version=out.get("backend"))
|
|
81
|
+
except Exception as exc: # noqa: BLE001
|
|
82
|
+
return ToolResult(envelope=invocation.envelope,
|
|
83
|
+
invocation_id=invocation.invocation_id,
|
|
84
|
+
status="failed",
|
|
85
|
+
output={"error": str(exc)[:200]})
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Molecular structural alerts + DURC screening.
|
|
2
|
+
|
|
3
|
+
The SafetyEngine historically inspected *protocols* (BSL, reagents, steps) —
|
|
4
|
+
never *molecules*. This module gives it molecule-level vision: curated
|
|
5
|
+
toxicophore SMARTS alerts (Murakami/Benigni-style classics) and a DURC
|
|
6
|
+
(Dual-Use Research of Concern) text screen against the select-agent families.
|
|
7
|
+
|
|
8
|
+
RDKit is optional (P1): without it, `screen_smiles` reports
|
|
9
|
+
`status="no-rdkit"` and the gate passes with an explicit unverified marker —
|
|
10
|
+
never silently pretends to have checked.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import re
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
# Rules live in VERSIONED DATA (safety_rules.json), not code — the list
|
|
19
|
+
# scales by editing data (and later ingesting Benigni/Bosa + Toxtree
|
|
20
|
+
# rulebooks wholesale), diffs in git, and the version rides along in every
|
|
21
|
+
# gate decision so an audit knows WHICH rule set judged a molecule.
|
|
22
|
+
_RULES_PATH = Path(__file__).parent / "safety_rules.json"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
_MIN_ALERTS = [ # self-contained (the module-level _FALLBACK derives from
|
|
26
|
+
{"name": "aromatic_nitro", # ALERTS, which needs this very function —
|
|
27
|
+
"smarts": "c[N+](=O)[O-]", # referencing it here was a NameError when
|
|
28
|
+
"severity": "high", # the data file is missing. Minimal high-
|
|
29
|
+
"note": "builtin fallback"}, # severity set; version string says so.
|
|
30
|
+
{"name": "aziridine", "smarts": "C1CN1", "severity": "high",
|
|
31
|
+
"note": "builtin fallback"},
|
|
32
|
+
{"name": "mustard_like", "smarts": "ClCCS(=O)=O", "severity": "high",
|
|
33
|
+
"note": "builtin fallback"},
|
|
34
|
+
{"name": "hydrazine", "smarts": "NN", "severity": "high",
|
|
35
|
+
"note": "builtin fallback"},
|
|
36
|
+
]
|
|
37
|
+
_MIN_AGENTS = ["bacillus anthracis", "variola", "ebola", "yersinia pestis"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _load_rules() -> dict:
|
|
41
|
+
try:
|
|
42
|
+
return json.loads(_RULES_PATH.read_text())
|
|
43
|
+
except Exception:
|
|
44
|
+
return {"version": "builtin-fallback", "alerts": _MIN_ALERTS,
|
|
45
|
+
"select_agents": _MIN_AGENTS}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# (name, smarts, severity, note)
|
|
49
|
+
|
|
50
|
+
_RULES = _load_rules()
|
|
51
|
+
RULES_VERSION = _RULES["version"]
|
|
52
|
+
ALERTS = [(a["name"], a["smarts"], a["severity"], a["note"])
|
|
53
|
+
for a in _RULES["alerts"]]
|
|
54
|
+
_SELECT_AGENTS = _RULES["select_agents"]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def screen_smiles(smiles: str, intent: str = "") -> dict:
|
|
58
|
+
"""Toxicophore screen. Returns {status, hits:[{alert,severity,note}]}
|
|
59
|
+
where status is 'checked' | 'no-rdkit'. `intent` (free text, e.g. the
|
|
60
|
+
hypothesis mechanism) downgrades matching medium alerts to warnings."""
|
|
61
|
+
try:
|
|
62
|
+
from rdkit import Chem, RDLogger
|
|
63
|
+
RDLogger.DisableLog("rdApp.*")
|
|
64
|
+
except ImportError:
|
|
65
|
+
return {"status": "no-rdkit", "hits": [], "refuse": []}
|
|
66
|
+
mol = Chem.MolFromSmiles(smiles) if smiles else None
|
|
67
|
+
if mol is None:
|
|
68
|
+
return {"status": "checked", "hits": [], "refuse": [],
|
|
69
|
+
"note": "unparseable structure"}
|
|
70
|
+
intent_l = (intent or "").lower()
|
|
71
|
+
covalent_intent = any(w in intent_l for w in
|
|
72
|
+
("covalent", "warhead", "irreversible"))
|
|
73
|
+
hits, refuse = [], []
|
|
74
|
+
for name, smarts, severity, note in ALERTS:
|
|
75
|
+
try:
|
|
76
|
+
patt = Chem.MolFromSmarts(smarts)
|
|
77
|
+
if patt is not None and mol.HasSubstructMatch(patt):
|
|
78
|
+
downgraded = (severity == "medium" and covalent_intent)
|
|
79
|
+
h = {"alert": name, "severity": "warning" if downgraded
|
|
80
|
+
else severity, "note": note}
|
|
81
|
+
hits.append(h)
|
|
82
|
+
if severity == "hard" or (severity == "medium"
|
|
83
|
+
and not downgraded):
|
|
84
|
+
refuse.append(h)
|
|
85
|
+
except Exception:
|
|
86
|
+
continue
|
|
87
|
+
return {"status": "checked", "hits": hits, "refuse": refuse}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def durc_screen(text: str) -> list[str]:
|
|
91
|
+
"""Cheap, always-on: does this text name a select agent / toxin family?"""
|
|
92
|
+
t = (text or "").lower()
|
|
93
|
+
return [a for a in _SELECT_AGENTS if re.search(re.escape(a), t)]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# minimal fallback if the data file is missing (never silent: version says so)
|
|
97
|
+
_FALLBACK = [a for a in ALERTS if a[0] in ("aromatic_nitro", "aziridine",
|
|
98
|
+
"mustard_like", "hydrazine")]
|
|
99
|
+
_FALLBACK_AGENTS = ["bacillus anthracis", "variola", "ebola", "yersinia pestis"]
|
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""TDC ADMET Benchmark Group — frozen, scaffold-split, fully offline.
|
|
2
|
+
|
|
3
|
+
Three absorption/distribution endpoints (Caco-2 permeability, human
|
|
4
|
+
intestinal absorption, blood-brain barrier) with TDC's canonical scaffold
|
|
5
|
+
splits (20% held-out test) shipped as checksummed fixtures in
|
|
6
|
+
`frozen/admet/` (see MANIFEST.json for provenance + citations). This
|
|
7
|
+
replaces URL-chasing: deepchem's S3 has inconsistent per-object ACLs
|
|
8
|
+
(Caco2/Tox21 403 today), and CI must never need the network (P8).
|
|
9
|
+
|
|
10
|
+
The models tier ladder (Random/Mean/CharRidge) fits on train_val and is
|
|
11
|
+
scored on TDC's exact test folds — the same folds the TDC leaderboard
|
|
12
|
+
uses — so our floor-relative numbers are comparable to published ones
|
|
13
|
+
without trusting any live download.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import csv
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Iterator
|
|
20
|
+
|
|
21
|
+
FROZEN = Path(__file__).parent / "frozen" / "admet"
|
|
22
|
+
|
|
23
|
+
#: name -> task type (TDC ADMET Group)
|
|
24
|
+
ADMET_DATASETS: dict[str, str] = {
|
|
25
|
+
"caco2_wang": "regression", # log apparent permeability, n=906
|
|
26
|
+
"hia_hou": "classification", # human intestinal absorption, n=578
|
|
27
|
+
"bbb_martins": "classification", # blood-brain barrier, n=1,975
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ADMETSplitDataset:
|
|
32
|
+
"""Frozen TDC ADMET dataset: .train() / .test() yield (smiles, label)."""
|
|
33
|
+
|
|
34
|
+
def __init__(self, name: str, limit: int | None = None):
|
|
35
|
+
if name not in ADMET_DATASETS:
|
|
36
|
+
raise ValueError(f"unknown ADMET dataset: {name} "
|
|
37
|
+
f"(have {sorted(ADMET_DATASETS)})")
|
|
38
|
+
self.name = name
|
|
39
|
+
self.task = ADMET_DATASETS[name]
|
|
40
|
+
self.limit = limit
|
|
41
|
+
self.dir = FROZEN / name
|
|
42
|
+
|
|
43
|
+
def _rows(self, split: str) -> Iterator[tuple[str, float]]:
|
|
44
|
+
p = self.dir / f"{split}.csv"
|
|
45
|
+
if not p.exists():
|
|
46
|
+
raise FileNotFoundError(f"frozen fixture missing: {p}")
|
|
47
|
+
n = 0
|
|
48
|
+
with p.open(newline="", encoding="utf-8-sig") as f:
|
|
49
|
+
for row in csv.DictReader(f):
|
|
50
|
+
smi, y = (row.get("Drug") or "").strip(), row.get("Y")
|
|
51
|
+
if not smi or y in (None, "", "NA"):
|
|
52
|
+
continue
|
|
53
|
+
yield smi, float(y)
|
|
54
|
+
n += 1
|
|
55
|
+
if self.limit and n >= self.limit:
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
def train(self) -> Iterator[tuple[str, float]]:
|
|
59
|
+
return self._rows("train_val")
|
|
60
|
+
|
|
61
|
+
def test(self) -> Iterator[tuple[str, float]]:
|
|
62
|
+
return self._rows("test")
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""ChEMBL published-bioactivity dataset adapter (case-study data source).
|
|
2
|
+
|
|
3
|
+
Fetches real, published binding measurements for a target (default: EGFR /
|
|
4
|
+
CHEMBL203) from the ChEMBL web services, converts IC50 nM -> pIC50, caches
|
|
5
|
+
locally. These are values from actual experiments in published papers — the
|
|
6
|
+
ground truth for case study 01.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import csv
|
|
11
|
+
import math
|
|
12
|
+
import urllib.request
|
|
13
|
+
from collections.abc import Iterator
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
BASE = "https://www.ebi.ac.uk/chembl/api/data/activity.json"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def fetch_target_activities(target_chembl_id: str = "CHEMBL203",
|
|
21
|
+
cache_dir: str | Path = ".data",
|
|
22
|
+
max_records: int = 20000) -> Path:
|
|
23
|
+
"""Download published binding activities (pChEMBL >= 5 preferred) for a
|
|
24
|
+
target; cache as CSV. Returns the cache path.
|
|
25
|
+
|
|
26
|
+
Pagination follows ChEMBL's raw `page_meta.next` URL and rows are
|
|
27
|
+
deduplicated by activity_chembl_id — re-slicing the cursor string
|
|
28
|
+
silently repeated the first page and duplicated training rows
|
|
29
|
+
(the CS02/03 pagination bug, fixed at the source)."""
|
|
30
|
+
cache = Path(cache_dir) / f"chembl_{target_chembl_id}.csv"
|
|
31
|
+
if cache.exists():
|
|
32
|
+
return cache
|
|
33
|
+
cache.parent.mkdir(parents=True, exist_ok=True)
|
|
34
|
+
rows: list[dict[str, str]] = []
|
|
35
|
+
seen: set[str] = set()
|
|
36
|
+
url: str | None = (f"{BASE}?target_chembl_id={target_chembl_id}"
|
|
37
|
+
"&assay_type=B&limit=1000")
|
|
38
|
+
while url and len(rows) < max_records:
|
|
39
|
+
req = urllib.request.Request(url, headers={"Accept": "application/json"})
|
|
40
|
+
with urllib.request.urlopen(req, timeout=60) as resp: # noqa: S310
|
|
41
|
+
data = json_loads(resp.read())
|
|
42
|
+
activities = data.get("activities", [])
|
|
43
|
+
for a in activities:
|
|
44
|
+
smiles = a.get("canonical_smiles")
|
|
45
|
+
value = a.get("standard_value")
|
|
46
|
+
units = a.get("standard_units")
|
|
47
|
+
pc = a.get("pchembl_value")
|
|
48
|
+
if not smiles or value in (None, "None"):
|
|
49
|
+
continue
|
|
50
|
+
try:
|
|
51
|
+
v = float(value)
|
|
52
|
+
except (TypeError, ValueError):
|
|
53
|
+
continue
|
|
54
|
+
if units == "nM" and v > 0:
|
|
55
|
+
pic50 = -math.log10(v * 1e-9)
|
|
56
|
+
elif pc is not None:
|
|
57
|
+
pic50 = float(pc)
|
|
58
|
+
else:
|
|
59
|
+
continue
|
|
60
|
+
if math.isnan(pic50):
|
|
61
|
+
continue
|
|
62
|
+
# dedup by CONTENT — repeated pages replay identical rows
|
|
63
|
+
# (activity_chembl_id is null in list responses; and identical
|
|
64
|
+
# compound/assay/value IS the same measurement)
|
|
65
|
+
key = f"{smiles}|{pic50:.3f}|{a.get('assay_chembl_id', '')}"
|
|
66
|
+
if key in seen:
|
|
67
|
+
continue
|
|
68
|
+
seen.add(key)
|
|
69
|
+
rows.append({"smiles": smiles, "pic50": f"{pic50:.3f}",
|
|
70
|
+
"assay": a.get("assay_chembl_id", "")})
|
|
71
|
+
# follow the RAW next URL — do not re-derive the cursor
|
|
72
|
+
url = data.get("page_meta", {}).get("next")
|
|
73
|
+
if url and url.startswith("/"):
|
|
74
|
+
url = "https://www.ebi.ac.uk" + url # host-relative next links
|
|
75
|
+
if not activities:
|
|
76
|
+
url = None
|
|
77
|
+
with cache.open("w", newline="") as f:
|
|
78
|
+
w = csv.DictWriter(f, fieldnames=["smiles", "pic50", "assay"])
|
|
79
|
+
w.writeheader()
|
|
80
|
+
w.writerows(rows)
|
|
81
|
+
return cache
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def json_loads(b: bytes) -> dict:
|
|
85
|
+
import json
|
|
86
|
+
return json.loads(b)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ChemblDataset:
|
|
90
|
+
"""DatasetAdapter over the cached ChEMBL activities (pic50 regression)."""
|
|
91
|
+
|
|
92
|
+
name = "chembl-egfr"
|
|
93
|
+
task = "regression"
|
|
94
|
+
|
|
95
|
+
def __init__(self, target_chembl_id: str = "CHEMBL203",
|
|
96
|
+
cache_dir: str | Path = ".data", limit: int | None = None,
|
|
97
|
+
min_pic50: float | None = None):
|
|
98
|
+
path = fetch_target_activities(target_chembl_id, cache_dir)
|
|
99
|
+
self.records: list[tuple[str, float]] = []
|
|
100
|
+
with path.open(newline="") as f:
|
|
101
|
+
for row in csv.DictReader(f):
|
|
102
|
+
v = float(row["pic50"])
|
|
103
|
+
if min_pic50 is not None and v < min_pic50:
|
|
104
|
+
continue
|
|
105
|
+
self.records.append((row["smiles"], v))
|
|
106
|
+
if limit and len(self.records) >= limit:
|
|
107
|
+
break
|
|
108
|
+
|
|
109
|
+
def load(self) -> Iterator[tuple[str, float]]:
|
|
110
|
+
yield from self.records
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"provenance": "TDC ADMET Benchmark Group canonical scaffold splits (20% held-out test), extracted from Zenodo record 10.5281/zenodo.10372419 (ADMET-AI data package, tdc_admet_group_raw), archived 2024-07; upstream datasets via Therapeutics Data Commons (tdcommons.ai, NEURIPS 2021 Datasets & Benchmarks track).",
|
|
3
|
+
"citations": {
|
|
4
|
+
"caco2_wang": "Li, V.E. et al. / Wang, J. et al., J. Pharm. Sci. 94:2005 (Caco-2 permeability, n=906)",
|
|
5
|
+
"hia_hou": "Hou, T.J. & Lu, K., Curr. Drug Metab. 7:2006 (human intestinal absorption, n=578)",
|
|
6
|
+
"bbb_martins": "Martins, G.T. et al., ACS Chem. Neurosci. 6:2015 (blood-brain barrier, n=1,975)"
|
|
7
|
+
},
|
|
8
|
+
"license_note": "TDC redistributes under original-work terms with CC-BY attribution; frozen copies here retain citation strings \u2014 verify per-dataset TDC pages before redistribution beyond repo.",
|
|
9
|
+
"why_frozen": "deepchem S3 per-object ACLs are inconsistent (Caco2/Tox21 403); repo-tracked CSVs keep the models tier fully offline (P8), on the SAME scaffold folds the TDC leaderboard uses.",
|
|
10
|
+
"entries": [
|
|
11
|
+
{
|
|
12
|
+
"path": "bbb_martins/test.csv",
|
|
13
|
+
"bytes": 22353,
|
|
14
|
+
"sha256": "82d4fa96f671a8382e9d8e6de3dde8385b9f337854c83e6fde2e69a7be93754f",
|
|
15
|
+
"source_member": "data/tdc_admet_group_raw/admet_group/bbb_martins/test.csv"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "bbb_martins/train_val.csv",
|
|
19
|
+
"bytes": 107016,
|
|
20
|
+
"sha256": "5035139072311f4cb0a1a54cffe11bc727004886ace4629b98f6db20c431e4af",
|
|
21
|
+
"source_member": "data/tdc_admet_group_raw/admet_group/bbb_martins/train_val.csv"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "caco2_wang/test.csv",
|
|
25
|
+
"bytes": 17322,
|
|
26
|
+
"sha256": "5380c15b0dd9c11e22d3e3843083362d535dae36062dfee08056d3af4cb444df",
|
|
27
|
+
"source_member": "data/tdc_admet_group_raw/admet_group/caco2_wang/test.csv"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "caco2_wang/train_val.csv",
|
|
31
|
+
"bytes": 61694,
|
|
32
|
+
"sha256": "e0965b4a0617a3aa2978ef28794e3467d55655090f282a120355ea575ebed6b2",
|
|
33
|
+
"source_member": "data/tdc_admet_group_raw/admet_group/caco2_wang/train_val.csv"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "hia_hou/test.csv",
|
|
37
|
+
"bytes": 8149,
|
|
38
|
+
"sha256": "da702497c3c0a50dbdff77471517562a8813859f53f069ac5bb43126aa534351",
|
|
39
|
+
"source_member": "data/tdc_admet_group_raw/admet_group/hia_hou/test.csv"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "hia_hou/train_val.csv",
|
|
43
|
+
"bytes": 29694,
|
|
44
|
+
"sha256": "87f35dc1767174efa245ee71644229b5073a8490988527a3fe6d2f1e7522c7db",
|
|
45
|
+
"source_member": "data/tdc_admet_group_raw/admet_group/hia_hou/train_val.csv"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|