Spaces:
Sleeping
Sleeping
Shehan Makani commited on
Commit ·
b715fd9
1
Parent(s): 1b9fcb0
fix: fuzzy material name lookup + proper CORS wildcard via allow_origin_regex
Browse files- Add _resolve_ing() to outgassing/radiation/thermal modules: matches
'Kapton HN' → 'Kapton HN (Polyimide Film)' etc. Prevents false
conservative-default fallback for all materials in the DB.
- Replace https://*.vercel.app (literal, not a glob in Starlette) with
allow_origin_regex for Vercel preview URLs.
- api/main_v2.py +10 -1
- modules/outgassing.py +15 -2
- modules/radiation_stability.py +14 -2
- modules/thermal_cycling.py +14 -2
api/main_v2.py
CHANGED
|
@@ -25,7 +25,16 @@ app = FastAPI(
|
|
| 25 |
|
| 26 |
app.add_middleware(
|
| 27 |
CORSMiddleware,
|
| 28 |
-
allow_origins=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
allow_credentials=True, allow_methods=["*"], allow_headers=["*"],
|
| 30 |
)
|
| 31 |
|
|
|
|
| 25 |
|
| 26 |
app.add_middleware(
|
| 27 |
CORSMiddleware,
|
| 28 |
+
allow_origins=[
|
| 29 |
+
"http://localhost:5173",
|
| 30 |
+
"http://localhost:3001",
|
| 31 |
+
"https://chemenova.com",
|
| 32 |
+
"https://www.chemenova.com",
|
| 33 |
+
"https://app.chemenova.com",
|
| 34 |
+
"https://orbitchem.chemenova.com",
|
| 35 |
+
*_EXTRA_ORIGINS,
|
| 36 |
+
],
|
| 37 |
+
allow_origin_regex=r"https://orbitchem-web.*\.vercel\.app",
|
| 38 |
allow_credentials=True, allow_methods=["*"], allow_headers=["*"],
|
| 39 |
)
|
| 40 |
|
modules/outgassing.py
CHANGED
|
@@ -126,6 +126,18 @@ def _risk_level(tml: float, cvcm: float) -> str:
|
|
| 126 |
return "low"
|
| 127 |
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
def run_outgassing_screen(
|
| 130 |
blend: Dict[str, float],
|
| 131 |
db: pd.DataFrame,
|
|
@@ -144,13 +156,14 @@ def run_outgassing_screen(
|
|
| 144 |
for ing, pct in blend.items():
|
| 145 |
mass_frac = float(pct) / total_pct
|
| 146 |
|
| 147 |
-
|
|
|
|
| 148 |
warnings.append(f"'{ing}' not in DB — using high-conservative outgassing defaults.")
|
| 149 |
vp_ref = 1.0 # 1 Pa default (moderately volatile)
|
| 150 |
mw = 150.0
|
| 151 |
dH = 40000.0
|
| 152 |
else:
|
| 153 |
-
row = idx.loc[
|
| 154 |
def _g(key, default):
|
| 155 |
try:
|
| 156 |
v = row.get(key, default)
|
|
|
|
| 126 |
return "low"
|
| 127 |
|
| 128 |
|
| 129 |
+
def _resolve_ing(ing: str, idx) -> str | None:
|
| 130 |
+
"""Match blend name against DB index, handling parenthetical suffixes."""
|
| 131 |
+
if ing in idx.index:
|
| 132 |
+
return ing
|
| 133 |
+
ing_l = ing.lower()
|
| 134 |
+
for key in idx.index:
|
| 135 |
+
key_l = key.lower()
|
| 136 |
+
if key_l.startswith(ing_l) or ing_l.startswith(key_l):
|
| 137 |
+
return key
|
| 138 |
+
return None
|
| 139 |
+
|
| 140 |
+
|
| 141 |
def run_outgassing_screen(
|
| 142 |
blend: Dict[str, float],
|
| 143 |
db: pd.DataFrame,
|
|
|
|
| 156 |
for ing, pct in blend.items():
|
| 157 |
mass_frac = float(pct) / total_pct
|
| 158 |
|
| 159 |
+
matched = _resolve_ing(ing, idx)
|
| 160 |
+
if matched is None:
|
| 161 |
warnings.append(f"'{ing}' not in DB — using high-conservative outgassing defaults.")
|
| 162 |
vp_ref = 1.0 # 1 Pa default (moderately volatile)
|
| 163 |
mw = 150.0
|
| 164 |
dH = 40000.0
|
| 165 |
else:
|
| 166 |
+
row = idx.loc[matched]
|
| 167 |
def _g(key, default):
|
| 168 |
try:
|
| 169 |
v = row.get(key, default)
|
modules/radiation_stability.py
CHANGED
|
@@ -86,6 +86,17 @@ class RadiationStabilityReport:
|
|
| 86 |
notes: List[str] = field(default_factory=list)
|
| 87 |
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
def _infer_polymer_class(smiles: str) -> str:
|
| 90 |
"""Infer polymer backbone class from SMILES pattern matching."""
|
| 91 |
if not RDKIT_OK or not smiles:
|
|
@@ -180,8 +191,9 @@ def run_radiation_stability(
|
|
| 180 |
smiles = ""
|
| 181 |
ring_count = 0
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
|
|
|
| 185 |
smiles = str(row.get("SMILES", "") or "")
|
| 186 |
|
| 187 |
polymer_cls = _infer_polymer_class(smiles)
|
|
|
|
| 86 |
notes: List[str] = field(default_factory=list)
|
| 87 |
|
| 88 |
|
| 89 |
+
def _resolve_ing(ing: str, idx) -> str | None:
|
| 90 |
+
if ing in idx.index:
|
| 91 |
+
return ing
|
| 92 |
+
ing_l = ing.lower()
|
| 93 |
+
for key in idx.index:
|
| 94 |
+
key_l = key.lower()
|
| 95 |
+
if key_l.startswith(ing_l) or ing_l.startswith(key_l):
|
| 96 |
+
return key
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
|
| 100 |
def _infer_polymer_class(smiles: str) -> str:
|
| 101 |
"""Infer polymer backbone class from SMILES pattern matching."""
|
| 102 |
if not RDKIT_OK or not smiles:
|
|
|
|
| 191 |
smiles = ""
|
| 192 |
ring_count = 0
|
| 193 |
|
| 194 |
+
matched = _resolve_ing(ing, idx)
|
| 195 |
+
if matched is not None:
|
| 196 |
+
row = idx.loc[matched]
|
| 197 |
smiles = str(row.get("SMILES", "") or "")
|
| 198 |
|
| 199 |
polymer_cls = _infer_polymer_class(smiles)
|
modules/thermal_cycling.py
CHANGED
|
@@ -112,6 +112,17 @@ def _delamination_G(
|
|
| 112 |
return round(E_GPa * 1e9 * (strain ** 2) * thickness_m / 2.0, 3)
|
| 113 |
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
def run_thermal_cycling(
|
| 116 |
blend: Dict[str, float],
|
| 117 |
db: pd.DataFrame,
|
|
@@ -149,8 +160,9 @@ def run_thermal_cycling(
|
|
| 149 |
E = 2.0 # GPa
|
| 150 |
uts = 40.0 # MPa
|
| 151 |
|
| 152 |
-
|
| 153 |
-
|
|
|
|
| 154 |
def _g(key, default):
|
| 155 |
try:
|
| 156 |
v = row.get(key, default)
|
|
|
|
| 112 |
return round(E_GPa * 1e9 * (strain ** 2) * thickness_m / 2.0, 3)
|
| 113 |
|
| 114 |
|
| 115 |
+
def _resolve_ing(ing: str, idx) -> str | None:
|
| 116 |
+
if ing in idx.index:
|
| 117 |
+
return ing
|
| 118 |
+
ing_l = ing.lower()
|
| 119 |
+
for key in idx.index:
|
| 120 |
+
key_l = key.lower()
|
| 121 |
+
if key_l.startswith(ing_l) or ing_l.startswith(key_l):
|
| 122 |
+
return key
|
| 123 |
+
return None
|
| 124 |
+
|
| 125 |
+
|
| 126 |
def run_thermal_cycling(
|
| 127 |
blend: Dict[str, float],
|
| 128 |
db: pd.DataFrame,
|
|
|
|
| 160 |
E = 2.0 # GPa
|
| 161 |
uts = 40.0 # MPa
|
| 162 |
|
| 163 |
+
matched = _resolve_ing(ing, idx)
|
| 164 |
+
if matched is not None:
|
| 165 |
+
row = idx.loc[matched]
|
| 166 |
def _g(key, default):
|
| 167 |
try:
|
| 168 |
v = row.get(key, default)
|