Skip to content

Commit

Permalink
Preserve custom seq across features
Browse files Browse the repository at this point in the history
  • Loading branch information
liambai committed Nov 9, 2024
1 parent ce4c326 commit 0aef5ec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion viz/src/SAEContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export const SAEProvider = ({ children }: { children: React.ReactNode }) => {
setSelectedFeature: (feature: number | undefined) => {
setSelectedFeature(feature);
if (feature !== undefined) {
navigate(`/sae-viz/${selectedModel}/${feature}`);
const seqMatch = path.match(/\?seq=([^&]+)/);
const seq = seqMatch ? seqMatch[1] : "";
const seqParam = seq ? `?seq=${seq}` : "";
navigate(`/sae-viz/${selectedModel}/${feature}${seqParam}`);
}
},
SAEConfig: SAE_CONFIGS[selectedModel],
Expand Down
6 changes: 3 additions & 3 deletions viz/src/components/CustomStructureViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Color } from "molstar/lib/mol-util/color";
import { redColorMapRGB } from "@/utils.ts";
import proteinEmoji from "../protein.png";
import { useIsMobile } from "@/hooks/use-mobile";
import { ESMFoldCache } from "@/utils";

interface CustomStructureViewerProps {
viewerId: string;
Expand All @@ -27,7 +28,6 @@ const CustomStructureViewer = ({
const [warning, setWarning] = useState("");
const isMobile = useIsMobile();

const ESMFoldCache = useRef<Record<string, string>>({});
const pluginRef = useRef<PluginContext | null>(null);

const createResidueColorTheme = (activationList: number[], name = "residue-colors") => {
Expand Down Expand Up @@ -156,8 +156,8 @@ const CustomStructureViewer = ({
const renderStructure = async () => {
setIsLoading(true);
try {
const pdbData = ESMFoldCache.current[seq] || (await foldStructure(seq));
ESMFoldCache.current[seq] = pdbData;
const pdbData = ESMFoldCache[seq] || (await foldStructure(seq));
ESMFoldCache[seq] = pdbData;
renderViewer(pdbData);
} catch (error) {
console.error("Error folding sequence:", error);
Expand Down
2 changes: 2 additions & 0 deletions viz/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ export function tokensToSequence(tokens: Array<number>): string {
export function sequenceToTokens(sequence: string): Array<number> {
return sequence.split("").map((residue) => residueToToken(residue));
}

export const ESMFoldCache: Record<string, string> = {};

0 comments on commit 0aef5ec

Please sign in to comment.