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.
Files changed (200) hide show
  1. proef/__init__.py +25 -0
  2. proef/acquisition.py +244 -0
  3. proef/ad.py +159 -0
  4. proef/adapters/__init__.py +0 -0
  5. proef/adapters/admet.py +196 -0
  6. proef/adapters/bio/__init__.py +0 -0
  7. proef/adapters/bio/rdkit_ops.py +52 -0
  8. proef/adapters/bio/safety_rules.json +146 -0
  9. proef/adapters/bio/seq_alerts.py +79 -0
  10. proef/adapters/bio/structure_score.py +85 -0
  11. proef/adapters/bio/tox_alerts.py +99 -0
  12. proef/adapters/data/__init__.py +0 -0
  13. proef/adapters/data/admet.py +62 -0
  14. proef/adapters/data/chembl.py +110 -0
  15. proef/adapters/data/frozen/admet/MANIFEST.json +48 -0
  16. proef/adapters/data/frozen/admet/bbb_martins/test.csv +407 -0
  17. proef/adapters/data/frozen/admet/bbb_martins/train_val.csv +1625 -0
  18. proef/adapters/data/frozen/admet/caco2_wang/test.csv +183 -0
  19. proef/adapters/data/frozen/admet/caco2_wang/train_val.csv +729 -0
  20. proef/adapters/data/frozen/admet/hia_hou/test.csv +118 -0
  21. proef/adapters/data/frozen/admet/hia_hou/train_val.csv +462 -0
  22. proef/adapters/data/moleculenet.py +60 -0
  23. proef/adapters/databases/__init__.py +0 -0
  24. proef/adapters/databases/chembl_gates.py +121 -0
  25. proef/adapters/databases/chembl_lookup.py +35 -0
  26. proef/adapters/databases/open_targets.py +102 -0
  27. proef/adapters/databases/pubmed.py +94 -0
  28. proef/adapters/devices/__init__.py +0 -0
  29. proef/adapters/devices/ezo_ph.py +251 -0
  30. proef/adapters/devices/hcs_microscope.py +143 -0
  31. proef/adapters/devices/lcms.py +123 -0
  32. proef/adapters/devices/scheduler.py +84 -0
  33. proef/adapters/devices/sila2.py +134 -0
  34. proef/adapters/genomics/alphagenome.py +146 -0
  35. proef/adapters/lab/__init__.py +0 -0
  36. proef/adapters/lab/bioprocess.py +32 -0
  37. proef/adapters/lab/devices.py +170 -0
  38. proef/adapters/lab/imaging.py +226 -0
  39. proef/adapters/lab/mhs_driver.py +124 -0
  40. proef/adapters/lab/opentrons.py +222 -0
  41. proef/adapters/lab/ot2_sim.py +174 -0
  42. proef/adapters/lab/plate_reader_share.py +108 -0
  43. proef/adapters/lab/protein_design.py +199 -0
  44. proef/adapters/lab/recording.py +119 -0
  45. proef/adapters/lab/replay.py +107 -0
  46. proef/adapters/lab/simulator.py +282 -0
  47. proef/adapters/lab/synthesis.py +92 -0
  48. proef/adapters/models/__init__.py +0 -0
  49. proef/adapters/models/anthropic_provider.py +157 -0
  50. proef/adapters/models/assayloop_ranker.py +67 -0
  51. proef/adapters/models/from_env.py +93 -0
  52. proef/adapters/models/gp_policy.py +93 -0
  53. proef/adapters/models/gp_policy_gp.py +36 -0
  54. proef/adapters/models/llm_policy.py +187 -0
  55. proef/adapters/models/openai_compat.py +150 -0
  56. proef/adapters/models/sklearn_policy.py +65 -0
  57. proef/adapters/retrosynthesis.py +247 -0
  58. proef/adapters/sandbox/__init__.py +20 -0
  59. proef/adapters/sandbox/agentenv.py +145 -0
  60. proef/adapters/sandbox/docker.py +217 -0
  61. proef/adapters/sandbox/local.py +164 -0
  62. proef/adapters/sandbox/opensandbox.py +122 -0
  63. proef/adapters/store/__init__.py +0 -0
  64. proef/adapters/store/sqlite.py +207 -0
  65. proef/adaptive.py +108 -0
  66. proef/advisory.py +76 -0
  67. proef/analysis_profiles/__init__.py +8 -0
  68. proef/analysis_profiles/measurements.py +266 -0
  69. proef/analysis_profiles/plate_assay.py +316 -0
  70. proef/analysis_report.py +195 -0
  71. proef/analysis_store.py +183 -0
  72. proef/anchor.py +154 -0
  73. proef/api/app.py +107 -0
  74. proef/api/launch.py +170 -0
  75. proef/api/v1/__init__.py +29 -0
  76. proef/api/v1/analyses.py +367 -0
  77. proef/api/v1/campaigns.py +802 -0
  78. proef/api/v1/deps.py +10 -0
  79. proef/api/v1/evals.py +16 -0
  80. proef/api/v1/evidence.py +132 -0
  81. proef/api/v1/governance.py +35 -0
  82. proef/api/v1/inbox.py +119 -0
  83. proef/api/v1/lab.py +110 -0
  84. proef/api/v1/pauses.py +77 -0
  85. proef/api/v1/programs.py +397 -0
  86. proef/api/v1/results.py +147 -0
  87. proef/api/v1/schemas.py +932 -0
  88. proef/api/v1/system.py +79 -0
  89. proef/api/v1/trees.py +216 -0
  90. proef/api/wizard_sessions.py +253 -0
  91. proef/approvals.py +102 -0
  92. proef/assays/__init__.py +15 -0
  93. proef/assays/dls.py +114 -0
  94. proef/assays/dsf.py +81 -0
  95. proef/assays/elisa.py +58 -0
  96. proef/assays/properties.py +65 -0
  97. proef/assays/simulate.py +157 -0
  98. proef/audit.py +152 -0
  99. proef/autoloop.py +1620 -0
  100. proef/benchmark.py +442 -0
  101. proef/campaign_fsm.py +151 -0
  102. proef/citations.py +141 -0
  103. proef/cli.py +1249 -0
  104. proef/connect.py +74 -0
  105. proef/core/__init__.py +0 -0
  106. proef/core/contracts/__init__.py +35 -0
  107. proef/core/contracts/analysis.py +100 -0
  108. proef/core/contracts/models.py +395 -0
  109. proef/core/device_card.py +125 -0
  110. proef/core/hypothesis.py +720 -0
  111. proef/core/interfaces.py +164 -0
  112. proef/core/registry.py +123 -0
  113. proef/core/safety.py +324 -0
  114. proef/core/workflow.py +159 -0
  115. proef/critic.py +62 -0
  116. proef/demo.py +164 -0
  117. proef/derivation.py +128 -0
  118. proef/diary.py +301 -0
  119. proef/eln.py +87 -0
  120. proef/evals/__init__.py +1 -0
  121. proef/evals/hallucination.py +86 -0
  122. proef/evals/harness.py +358 -0
  123. proef/evals/orchestration.py +254 -0
  124. proef/evals/tasks.py +1010 -0
  125. proef/evals/toolcalls.py +425 -0
  126. proef/experiment.py +172 -0
  127. proef/experiment_analysis.py +114 -0
  128. proef/experiments/__init__.py +0 -0
  129. proef/experiments/grounding_exp.py +689 -0
  130. proef/figures.py +218 -0
  131. proef/fitting.py +309 -0
  132. proef/fixtures.py +140 -0
  133. proef/flywheel.py +125 -0
  134. proef/followup.py +126 -0
  135. proef/governance.py +290 -0
  136. proef/groundedness.py +361 -0
  137. proef/grounding.py +202 -0
  138. proef/hypothesis_agent.py +369 -0
  139. proef/ingest.py +157 -0
  140. proef/instruments.json +173 -0
  141. proef/interpret.py +95 -0
  142. proef/kinetic.py +102 -0
  143. proef/labread/__init__.py +45 -0
  144. proef/labread/analysis.py +428 -0
  145. proef/labread/common.py +153 -0
  146. proef/labread/formats.py +190 -0
  147. proef/labread/layout.py +168 -0
  148. proef/labread/pubchem.py +179 -0
  149. proef/labselect.py +431 -0
  150. proef/materials.py +140 -0
  151. proef/mcp_instrument.py +396 -0
  152. proef/mcp_server.py +283 -0
  153. proef/modality.py +111 -0
  154. proef/model_guard.py +245 -0
  155. proef/output_blocks.py +183 -0
  156. proef/paths.py +32 -0
  157. proef/physfail.py +55 -0
  158. proef/plan.py +160 -0
  159. proef/plots.py +123 -0
  160. proef/predictors.py +217 -0
  161. proef/probes.py +79 -0
  162. proef/problem_tree.py +581 -0
  163. proef/program.py +308 -0
  164. proef/protocol_design.py +42 -0
  165. proef/proxy.py +78 -0
  166. proef/readiness.py +259 -0
  167. proef/reliability.py +49 -0
  168. proef/report.py +117 -0
  169. proef/reproduce.py +310 -0
  170. proef/reviewer.py +254 -0
  171. proef/sandbox_session.py +247 -0
  172. proef/sandboxd.py +109 -0
  173. proef/scaffold.py +195 -0
  174. proef/series.py +327 -0
  175. proef/skills.py +203 -0
  176. proef/sweep.py +83 -0
  177. proef/taste.py +177 -0
  178. proef/templates/confirmatory-followup.json +34 -0
  179. proef/templates/dose-response-screen.json +39 -0
  180. proef/templates/sar-exploration.json +38 -0
  181. proef/templates.py +124 -0
  182. proef/toolkit.py +433 -0
  183. proef/toolloop.py +133 -0
  184. proef/tools.py +441 -0
  185. proef/tpp.py +185 -0
  186. proef/views/__init__.py +14 -0
  187. proef/views/counts.py +102 -0
  188. proef/views/experiment.py +154 -0
  189. proef/views/ids.py +49 -0
  190. proef/views/narrative.py +294 -0
  191. proef/views/pipeline.py +370 -0
  192. proef/vision.py +165 -0
  193. proef/watch.py +790 -0
  194. proef/wizard_chain.py +25 -0
  195. proef/wizard_store.py +373 -0
  196. proef-0.2.0.dist-info/METADATA +662 -0
  197. proef-0.2.0.dist-info/RECORD +200 -0
  198. proef-0.2.0.dist-info/WHEEL +4 -0
  199. proef-0.2.0.dist-info/entry_points.txt +14 -0
  200. proef-0.2.0.dist-info/licenses/LICENSE +202 -0
proef/citations.py ADDED
@@ -0,0 +1,141 @@
1
+ """Citation verification — enforce the "never invent" rule.
2
+
3
+ A hypothesis may cite a PMID or DOI to ground its rationale. This module
4
+ checks that the citation EXISTS (PMID resolvable / DOI indexed) via PubMed
5
+ E-utilities, with a local content-addressed cache so repeat runs are free
6
+ and offline runs degrade to "check-failed" — never to a false "invalid".
7
+
8
+ Statuses:
9
+ verified citation resolves to a real publication
10
+ invalid checked online, no such publication (hallucination)
11
+ check-failed offline/timeout — unknown, treated as unverified (no bonus)
12
+ unverified never checked
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import re
18
+ import urllib.parse
19
+ import urllib.error
20
+ import urllib.request
21
+ from pathlib import Path
22
+
23
+ CACHE = Path(".data/citations.json")
24
+ EUTILS = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils"
25
+
26
+ CHEMBL_RE = re.compile(r"\b(CHEMBL\d+)\b", re.I)
27
+ PMID_RE = re.compile(r"\bpmid[:\s]*(\d{5,9})\b", re.I) # the label is required and the digits must not sit inside another token (CHEMBL428690)
28
+ DOI_RE = re.compile(r"\b(10\.\d{4,9}/[^\s\"')>]+)\b")
29
+
30
+
31
+ def parse(citation: str) -> tuple[str, str] | None:
32
+ """('pmid', '35377565') or ('doi', '10.1021/...') or None."""
33
+ citation = citation.strip()
34
+ m = DOI_RE.search(citation)
35
+ if m:
36
+ return ("doi", m.group(1).rstrip(".,;"))
37
+ m = PMID_RE.search(citation)
38
+ if m:
39
+ return ("pmid", m.group(1))
40
+ if citation.isdigit():
41
+ return ("pmid", citation)
42
+ m = CHEMBL_RE.search(citation)
43
+ if m: # a ChEMBL id (molecule, target, document or assay): the lookup endpoint resolves any of them
44
+ return ("chembl", m.group(1).upper())
45
+ return None
46
+
47
+
48
+ def _default_fetch(url: str) -> bytes:
49
+ req = urllib.request.Request(url, headers={"Accept": "application/json"})
50
+ with urllib.request.urlopen(req, timeout=30) as r: # noqa: S310
51
+ return r.read()
52
+
53
+
54
+ def _load_cache() -> dict:
55
+ try:
56
+ return json.loads(CACHE.read_text())
57
+ except Exception:
58
+ return {}
59
+
60
+
61
+ def _save_cache(c: dict) -> None:
62
+ CACHE.parent.mkdir(parents=True, exist_ok=True)
63
+ CACHE.write_text(json.dumps(c, indent=1))
64
+
65
+
66
+ def verify(citation: str, fetch: callable = _default_fetch) -> dict:
67
+ """Resolve one citation. Returns {status, kind, detail}."""
68
+ parsed = parse(citation)
69
+ if not parsed:
70
+ return {"status": "invalid", "kind": "unparseable",
71
+ "detail": "not a PMID or DOI"}
72
+ kind, value = parsed
73
+ cache = _load_cache()
74
+ key = f"{kind}:{value}"
75
+ if key in cache:
76
+ return cache[key]
77
+ try:
78
+ if kind == "pmid":
79
+ url = (f"{EUTILS}/esummary.fcgi?version=2.0&id={value}"
80
+ "&db=pubmed&retmode=json")
81
+ data = json.loads(fetch(url))
82
+ rec = data.get("result", {}).get(value)
83
+ if rec and rec.get("title"):
84
+ out = {"status": "verified", "kind": kind,
85
+ "detail": f"{rec.get('pubdate', '')[:4]} · "
86
+ f"{(rec.get('source') or '')[:40]}"}
87
+ else:
88
+ out = {"status": "invalid", "kind": kind,
89
+ "detail": "PMID not found"}
90
+ elif kind == "chembl":
91
+ data = json.loads(fetch(f"https://www.ebi.ac.uk/chembl/api/data/chembl_id_lookup/{value}.json"))
92
+ out = ({"status": "verified", "kind": kind, "detail": str(data.get("entity_type") or "")[:40]} if data.get("chembl_id") else
93
+ {"status": "invalid", "kind": kind, "detail": "ChEMBL id not found"})
94
+ else:
95
+ term = urllib.parse.quote(f"{value}[DOI]")
96
+ url = f"{EUTILS}/esearch.fcgi?db=pubmed&retmode=json&term={term}"
97
+ data = json.loads(fetch(url))
98
+ ids = data.get("esearchresult", {}).get("idlist", [])
99
+ out = ({"status": "verified", "kind": kind,
100
+ "detail": f"PMID {ids[0]}"} if ids else
101
+ {"status": "invalid", "kind": kind,
102
+ "detail": "DOI not indexed"})
103
+ except urllib.error.HTTPError as exc:
104
+ if exc.code == 404: # the service answered: there is no such record (a fake id)
105
+ out = {"status": "invalid", "kind": kind, "detail": f"{kind} not found (HTTP 404)"}
106
+ else:
107
+ return {"status": "check-failed", "kind": kind, "detail": f"HTTP {exc.code}"}
108
+ except Exception as exc:
109
+ # network failure is NOT evidence of a fake citation
110
+ return {"status": "check-failed", "kind": kind,
111
+ "detail": str(exc)[:80]}
112
+ if out["status"] != "check-failed":
113
+ cache[key] = out
114
+ _save_cache(cache)
115
+ return out
116
+
117
+
118
+ def ids_of(citation: str) -> list[tuple[str, str]]:
119
+ """Every identifier in a citation string, in order, each as (kind, value): a model often writes several ('PMID 1; CHEMBL2; 10.x/y')."""
120
+ out: list[tuple[str, str]] = []
121
+ for m in re.finditer(r"(10\.\d{4,9}/[^\s\";,)>]+)|\bpmid[:\s]*(\d{5,9})\b|\b(CHEMBL\d+)\b", citation or "", re.I):
122
+ item = ("doi", m.group(1).rstrip(".,;")) if m.group(1) else ("pmid", m.group(2)) if m.group(2) else ("chembl", m.group(3).upper())
123
+ if item not in out:
124
+ out.append(item)
125
+ return out
126
+
127
+
128
+ def verify_each(citation: str, fetch: callable = _default_fetch) -> dict:
129
+ """A citation that names several things is verified only if EVERY one resolves: any id that does not exist makes it invalid; an unreachable
130
+ service on any makes it check-failed. (`verify` looks at the first identifier only.)"""
131
+ ids = ids_of(citation)
132
+ if not ids:
133
+ return verify(citation, fetch)
134
+ results = [verify(f"PMID {v}" if k == "pmid" else v, fetch) for k, v in ids]
135
+ status = ("invalid" if any(r["status"] == "invalid" for r in results) else "check-failed" if any(r["status"] == "check-failed" for r in results)
136
+ else "verified")
137
+ return {"status": status, "kind": "multi" if len(ids) > 1 else ids[0][0], "detail": f"{len(ids)} identifier(s): " + ", ".join(r["status"] for r in results)}
138
+
139
+
140
+ def verify_many(citations: list[str], fetch=_default_fetch) -> dict[str, dict]:
141
+ return {c: verify(c, fetch) for c in citations if c}