import {useCallback, useEffect, useRef, useState} from 'react'; import {useMotion} from './Motion'; import type {ProteinCase} from './types'; type Point={x:number;y:number;z:number}; /** Interpolate the actual Cα coordinates for orientation, not simulated folding dynamics. */ export function SequenceFold({protein}:{protein:ProteinCase}){ const host=useRef(null), canvas=useRef(null); const phase=useRef(0),angle=useRef(.4),drawingSize=useRef({w:800,h:300,dpr:1}); const [points,setPoints]=useState([]),[visible,setVisible]=useState(false),[load,setLoad]=useState(false),[error,setError]=useState(false); const {enabled,reduced}=useMotion(); const [percent,setPercent]=useState(()=>reduced?100:0),[playing,setPlaying]=useState(()=>!reduced); const drag=useRef<{x:number;angle:number}|null>(null); useEffect(()=>{ const observer=new IntersectionObserver(([entry])=>{setVisible(entry.isIntersecting);if(entry.isIntersecting)setLoad(true);},{rootMargin:'0px',threshold:.1}); if(host.current)observer.observe(host.current); return()=>observer.disconnect(); },[]); useEffect(()=>{ if(!load)return; const ac=new AbortController(); fetch(protein.pdbUrl,{signal:ac.signal}).then(r=>{if(!r.ok)throw new Error('Structure unavailable');return r.text();}).then(text=>{ const coords=text.split('\n').filter(line=>line.startsWith('ATOM ')&&line.slice(12,16).trim()==='CA').map(line=>({x:Number(line.slice(30,38)),y:Number(line.slice(38,46)),z:Number(line.slice(46,54))})); if(coords.length!==protein.length||coords.some(p=>!Number.isFinite(p.x+p.y+p.z)))throw new Error('Invalid backbone'); const center=coords.reduce((a,p)=>({x:a.x+p.x/coords.length,y:a.y+p.y/coords.length,z:a.z+p.z/coords.length}),{x:0,y:0,z:0}); setPoints(coords.map(p=>({x:p.x-center.x,y:p.y-center.y,z:p.z-center.z}))); }).catch(()=>{if(!ac.signal.aborted)setError(true);}); return()=>ac.abort(); },[load,protein.pdbUrl,protein.length]); const draw=useCallback(()=>{ const ctx=canvas.current?.getContext('2d');if(!ctx)return; const {w,h,dpr}=drawingSize.current; ctx.setTransform(dpr,0,0,dpr,0,0);ctx.clearRect(0,0,w,h); if(!points.length)return; const p=phase.current, ease=p*p*(3-2*p); const cos=Math.cos(angle.current),sin=Math.sin(angle.current); const rotated=points.map(v=>{ const x=v.x*cos-v.z*sin,z=v.x*sin+v.z*cos; const y=v.y*Math.cos(.45)-z*Math.sin(.45); return {x:x*Math.cos(.3)-y*Math.sin(.3),y:x*Math.sin(.3)+y*Math.cos(.3),z}; }); const minX=Math.min(...rotated.map(v=>v.x)),maxX=Math.max(...rotated.map(v=>v.x)); const minY=Math.min(...rotated.map(v=>v.y)),maxY=Math.max(...rotated.map(v=>v.y)); const scale=Math.min((w-65)/(maxX-minX),(h-70)/(maxY-minY)); const projected=rotated.map((v,i)=>{ const x=(v.x-(minX+maxX)/2)*scale,y=(v.y-(minY+maxY)/2)*scale; const lineX=(i/(points.length-1)-.5)*(w-50); const lineY=Math.sin(i/(points.length-1)*Math.PI*5)*12; return {x:w/2+lineX*(1-ease)+x*ease,y:h/2+lineY*(1-ease)+y*ease,z:v.z*ease}; }); // Subtle coordinate field anchors the molecular silhouette. ctx.strokeStyle='#aabbcb1a';ctx.lineWidth=1; for(let x=24;x{ ctx.fillStyle=`hsl(${35-i/points.length*29}, 66%, ${66+v.z/20}%)`; ctx.beginPath();ctx.arc(v.x,v.y,(1.3+ease*.8),0,Math.PI*2);ctx.fill(); }); const first=projected[0],last=projected.at(-1)!; ctx.font='11px "DM Sans", sans-serif';ctx.textAlign='center'; ctx.fillStyle='#f2bc7a';ctx.fillText('N',first.x,first.y-13); ctx.fillStyle='#f37f68';ctx.fillText('C',last.x,last.y+20); },[points]); useEffect(()=>{ if(!canvas.current)return; const el=canvas.current; const observer=new ResizeObserver(()=>{ const rect=el.getBoundingClientRect(),dpr=Math.min(devicePixelRatio||1,2); drawingSize.current={w:rect.width,h:rect.height,dpr}; el.width=Math.round(rect.width*dpr);el.height=Math.round(rect.height*dpr);draw(); });observer.observe(el);return()=>observer.disconnect(); },[draw]); useEffect(()=>{draw();},[draw,percent]); useEffect(()=>{if(reduced){phase.current=1;setPercent(100);setPlaying(false);draw();}},[reduced,draw]); useEffect(()=>{ if(!playing||!enabled||!visible||!points.length)return; let frame=0,last=0; const tick=(now:number)=>{ if(last)phase.current=Math.min(1,phase.current+Math.min(now-last,60)/8000); last=now;setPercent(Math.round(phase.current*100));draw(); if(phase.current<1)frame=requestAnimationFrame(tick);else setPlaying(false); }; frame=requestAnimationFrame(tick);return()=>cancelAnimationFrame(frame); },[playing,enabled,visible,points,draw]); const replay=()=>{if(phase.current>=1){phase.current=0;setPercent(0);}setPlaying(v=>!v);}; return

SEQUENCE → STRUCTURE

One sequence.
Another dimension.

Follow {protein.length} residues into the predicted backbone of DE2, then explore the design and its measured PET degradation products below.

{protein.id.toUpperCase()}{protein.length} amino acids
ESMFold-v1 prediction
Cα BACKBONE · N → C{percent===100?'PREDICTED STRUCTURE':percent===0?'SEQUENCE ORDER':'SEQUENCE → STRUCTURE'}
{drag.current={x:e.clientX,angle:angle.current};e.currentTarget.setPointerCapture(e.pointerId);}} onPointerMove={e=>{if(drag.current){angle.current=drag.current.angle+(e.clientX-drag.current.x)*.01;draw();}}} onPointerUp={()=>{drag.current=null;}} onPointerCancel={()=>{drag.current=null;}}/>{!points.length&&

{error?'Backbone preview unavailable. The structure explorer below remains available.':'Loading the predicted backbone…'}

}

Drag to rotate · Visual interpolation of predicted coordinates, not a simulated folding trajectory.

; }