3v324v23 Claude Code commited on
Commit
35f6c3d
·
1 Parent(s): 3b0da48

Remove dead code and untrack DS_Store

Browse files

- Remove if 0: debug/tracing blocks from CHRIS.py, ChemID.py, and qrf/qrf_train.py (236 lines of unreachable code)
- Remove commented-out v1 blueprint registrations (color_module, exposure_module) from CHRIS.py
- Untrack static/.DS_Store (already in .gitignore)

Co-Authored-By: Claude Code <noreply@anthropic.com>

Files changed (4) hide show
  1. CHRIS.py +0 -26
  2. ChemID.py +0 -206
  3. qrf/qrf_train.py +0 -4
  4. static/.DS_Store +0 -0
CHRIS.py CHANGED
@@ -11,32 +11,6 @@ app.debug = True
11
  # sort_by=("tottime",) # total time spent in function body
12
  #)
13
 
14
- ### DEBUGGING
15
- if 0:
16
- from pprint import pformat
17
- from flask import g, request
18
-
19
- @app.after_request
20
- def dump_chem_trace(response):
21
- trace = getattr(g, "chem_trace", None)
22
- if trace:
23
- bases = sorted(set(getattr(g, "chem_bases", [])))
24
- payload = {
25
- "path": request.path,
26
- "query": request.values.to_dict(flat=False),
27
- "base_urls": bases,
28
- "remote_trace": [x for x in trace if x.get("kind") == "remote"],
29
- "app_trace": [x for x in trace if x.get("kind") == "app"],
30
- }
31
- app.logger.warning("CHEMTRACE\n%s", pformat(payload, sort_dicts=False, width=120))
32
- return response
33
-
34
- #from color_module import blueprint
35
- #app.register_blueprint(blueprint)
36
-
37
- #from exposure_module import blueprint
38
- #app.register_blueprint(blueprint)
39
-
40
  from efficiency_module import blueprint
41
  app.register_blueprint(blueprint)
42
 
 
11
  # sort_by=("tottime",) # total time spent in function body
12
  #)
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  from efficiency_module import blueprint
15
  app.register_blueprint(blueprint)
16
 
ChemID.py CHANGED
@@ -74,178 +74,6 @@ def _cirpy_available(force=False):
74
  _cirpy_last_check = time.monotonic()
75
  return try_cirpy
76
 
77
- if 0:
78
- ## DEBUGGING
79
- import time
80
- import functools
81
- import inspect
82
- import logging
83
- import os
84
- import urllib.request
85
- import urllib.parse
86
-
87
- try:
88
- from flask import has_request_context, g
89
- except Exception:
90
- def has_request_context():
91
- return False
92
- g = None
93
-
94
- TRACE_THRESHOLD = float(os.environ.get("CHEM_TRACE_THRESHOLD", "0.0"))
95
-
96
- chemtrace_logger = logging.getLogger("chemtrace")
97
- if not chemtrace_logger.handlers:
98
- chemtrace_logger.setLevel(logging.INFO)
99
-
100
- def _short(x, n=200):
101
- s = repr(x)
102
- return s if len(s) <= n else s[:n-3] + "..."
103
-
104
- def _find_app_caller():
105
- for frame in inspect.stack()[2:]:
106
- fn = frame.filename.replace("\\", "/")
107
- if (
108
- "site-packages" not in fn
109
- and "/lib/python" not in fn
110
- and not fn.endswith("/logging/__init__.py")
111
- ):
112
- return {
113
- "file": os.path.basename(frame.filename),
114
- "func": frame.function,
115
- "line": frame.lineno,
116
- }
117
- return None
118
-
119
- def _url_info(url):
120
- if not url:
121
- return None
122
- try:
123
- parts = urllib.parse.urlsplit(str(url))
124
- base = f"{parts.scheme}://{parts.netloc}" if parts.scheme and parts.netloc else None
125
- return {
126
- "url": str(url),
127
- "base": base,
128
- "host": parts.netloc or None,
129
- "path": parts.path or "",
130
- }
131
- except Exception:
132
- return {"url": _short(url), "base": None, "host": None, "path": None}
133
-
134
- def _append_trace_event(event):
135
- if has_request_context():
136
- if getattr(g, "chem_trace", None) is None:
137
- g.chem_trace = []
138
- g.chem_trace.append(event)
139
-
140
- info = event.get("target")
141
- base = info.get("base") if isinstance(info, dict) else None
142
- if base:
143
- if getattr(g, "chem_bases", None) is None:
144
- g.chem_bases = []
145
- g.chem_bases.append(base)
146
- else:
147
- chemtrace_logger.info("%r", event)
148
-
149
- def trace_call(fn):
150
- @functools.wraps(fn)
151
- def wrapper(*args, **kwargs):
152
- t0 = time.perf_counter()
153
- ok = False
154
- err = None
155
- try:
156
- result = fn(*args, **kwargs)
157
- ok = True
158
- return result
159
- except Exception as e:
160
- err = f"{type(e).__name__}: {e}"
161
- raise
162
- finally:
163
- dt = time.perf_counter() - t0
164
- if dt >= TRACE_THRESHOLD:
165
- _append_trace_event({
166
- "kind": "app",
167
- "fn": fn.__name__,
168
- "secs": round(dt, 4),
169
- "arg0": _short(args[0]) if args else None,
170
- "ok": ok,
171
- "err": err,
172
- })
173
- return wrapper
174
-
175
- def trace_external(label, fn, formatter=None):
176
- @functools.wraps(fn)
177
- def wrapper(*args, **kwargs):
178
- t0 = time.perf_counter()
179
- ok = False
180
- err = None
181
- caller = _find_app_caller()
182
- target = None
183
- if formatter is not None:
184
- try:
185
- target = formatter(args, kwargs)
186
- except Exception:
187
- target = None
188
- try:
189
- result = fn(*args, **kwargs)
190
- ok = True
191
- return result
192
- except Exception as e:
193
- err = f"{type(e).__name__}: {e}"
194
- raise
195
- finally:
196
- dt = time.perf_counter() - t0
197
- if dt >= TRACE_THRESHOLD:
198
- _append_trace_event({
199
- "kind": "remote",
200
- "fn": label,
201
- "caller": caller,
202
- "target": target,
203
- "secs": round(dt, 4),
204
- "ok": ok,
205
- "err": err,
206
- })
207
- return wrapper
208
-
209
- def _fmt_urlopen(args, kwargs):
210
- url = args[0] if len(args) > 0 else kwargs.get("url")
211
- info = _url_info(url)
212
- if info is not None:
213
- info["timeout"] = kwargs.get("timeout")
214
- return info
215
-
216
- def _fmt_requests(args, kwargs):
217
- method = args[1] if len(args) > 1 else kwargs.get("method")
218
- url = args[2] if len(args) > 2 else kwargs.get("url")
219
- info = _url_info(url)
220
- if info is not None:
221
- info["method"] = method
222
- info["timeout"] = kwargs.get("timeout")
223
- return info
224
-
225
- def _fmt_selenium_get(args, kwargs):
226
- url = args[1] if len(args) > 1 else kwargs.get("url")
227
- return _url_info(url)
228
-
229
- def _fmt_pcp(args, kwargs):
230
- query = args[0] if len(args) > 0 else kwargs.get("identifier")
231
- namespace = args[1] if len(args) > 1 else kwargs.get("namespace")
232
- info = _url_info(getattr(pcp, "API_BASE", None)) or {}
233
- info.update({
234
- "query": _short(query),
235
- "namespace": namespace,
236
- })
237
- return info
238
-
239
- def _fmt_cirpy(args, kwargs):
240
- query = args[0] if len(args) > 0 else None
241
- resolver = args[1] if len(args) > 1 else kwargs.get("resolver")
242
- info = _url_info(getattr(cirpy, "API_BASE", None)) or {}
243
- info.update({
244
- "query": _short(query),
245
- "resolver": resolver,
246
- })
247
- return info
248
-
249
  ORGANIC_ATOM_SET = {5, 6, 7, 8, 9, 15, 16, 17, 35, 53}
250
  METAL_ATOM_SET = set([3,4,11,12,13] + list(range(19,31+1)) + list(range(37,50+1)) + list(range(55,84+1)) + list(range(87,114+1)) + [116])
251
  with open('data/ceramics_list.txt', 'r') as fp:
@@ -1525,37 +1353,3 @@ def getLogP(cas,mol):
1525
  LogP_origin = 'rdkit/calc'
1526
  return LogP, LogP_origin
1527
 
1528
- #### DEBUGGING
1529
- if 0:
1530
- ResolveChemical = trace_call(ResolveChemical)
1531
- smiles2name = trace_call(smiles2name)
1532
- cas2smiles = trace_call(cas2smiles)
1533
- cas2name = trace_call(cas2name)
1534
- name2iupac = trace_call(name2iupac)
1535
- name2cas = trace_call(name2cas)
1536
- name2smiles = trace_call(name2smiles)
1537
- string2density = trace_call(string2density)
1538
- string2mp = trace_call(string2mp)
1539
- mol2mp = trace_call(mol2mp)
1540
- if hasattr(pcp, "urlopen"):
1541
- pcp.urlopen = trace_external("pubchempy.urlopen", pcp.urlopen, _fmt_urlopen)
1542
-
1543
- if hasattr(cirpy, "urlopen"):
1544
- cirpy.urlopen = trace_external("cirpy.urlopen", cirpy.urlopen, _fmt_urlopen)
1545
-
1546
- pcp.get_compounds = trace_external("pcp.get_compounds", pcp.get_compounds, _fmt_pcp)
1547
- pcp.get_substances = trace_external("pcp.get_substances", pcp.get_substances, _fmt_pcp)
1548
- cirpy.resolve = trace_external("cirpy.resolve", cirpy.resolve, _fmt_cirpy)
1549
- urllib.request.urlopen = trace_external("urllib.request.urlopen", urllib.request.urlopen, _fmt_urlopen)
1550
- requests.sessions.Session.request = trace_external(
1551
- "requests.Session.request",
1552
- requests.sessions.Session.request,
1553
- _fmt_requests,
1554
- )
1555
-
1556
- if try_dsstox:
1557
- selenium.webdriver.Chrome.get = trace_external(
1558
- "selenium.webdriver.Chrome.get",
1559
- selenium.webdriver.Chrome.get,
1560
- _fmt_selenium_get,
1561
- )
 
74
  _cirpy_last_check = time.monotonic()
75
  return try_cirpy
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  ORGANIC_ATOM_SET = {5, 6, 7, 8, 9, 15, 16, 17, 35, 53}
78
  METAL_ATOM_SET = set([3,4,11,12,13] + list(range(19,31+1)) + list(range(37,50+1)) + list(range(55,84+1)) + list(range(87,114+1)) + [116])
79
  with open('data/ceramics_list.txt', 'r') as fp:
 
1353
  LogP_origin = 'rdkit/calc'
1354
  return LogP, LogP_origin
1355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
qrf/qrf_train.py CHANGED
@@ -37,10 +37,6 @@ for T_target in QRF_T_list:
37
  sub_desc_list = df_params.loc[mask_T, 'sub_desc_list'].iloc[0].split('|')
38
  params = df_params.loc[mask_T, ['bootstrap', 'max_depth', 'max_features', 'max_samples', 'min_samples_leaf', 'min_samples_split', 'n_estimators']].iloc[0].to_dict()
39
  params['max_samples'] = float(params['max_samples'])
40
- if 0:
41
- sub_desc_list = ['MW', 'Polymer_Tg', 'Polymer_Density', 'VR2_A', 'ATS0Z', 'AATS5d', 'BCUTv-1h', 'BCUTse-1l', 'Xch-7dv', 'Mp', 'Mi', 'SaasC', 'ETA_epsilon_5', 'fragCpx', 'JGI5', 'JGI8']
42
- params = {'bootstrap': True, 'max_depth': 7, 'max_features': 0.4, 'max_samples': 1.0, 'min_samples_leaf': 2, 'min_samples_split': 2, 'n_estimators': 1000} # best from -18-2.py w fout<0.040 (and 0.045)
43
-
44
  ## read data
45
  #df_X = pd.read_excel('qrf_x.xlsx')
46
  #df_y = pd.read_excel('qrf_y.xlsx')
 
37
  sub_desc_list = df_params.loc[mask_T, 'sub_desc_list'].iloc[0].split('|')
38
  params = df_params.loc[mask_T, ['bootstrap', 'max_depth', 'max_features', 'max_samples', 'min_samples_leaf', 'min_samples_split', 'n_estimators']].iloc[0].to_dict()
39
  params['max_samples'] = float(params['max_samples'])
 
 
 
 
40
  ## read data
41
  #df_X = pd.read_excel('qrf_x.xlsx')
42
  #df_y = pd.read_excel('qrf_y.xlsx')
static/.DS_Store DELETED
Binary file (6.15 kB)