Skip to content

Commit fb85b00

Browse files
AmirMohammad CheraghaliAmirMohammad Cheraghali
authored andcommitted
Enhance chemical metadata: Show 2D structure image for PubChem entries
1 parent 7a14f79 commit fb85b00

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/components/Controls.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,28 @@ export const Controls: React.FC<ControlsProps> = ({
597597
</div>
598598
)}
599599

600-
{/* Source / ID */}
600+
{/* Structure Image or Source */}
601601
<div
602602
className={`pt-1 border-t border-neutral-200 dark:border-neutral-800 ${(pdbMetadata.formula || pdbMetadata.molecularWeight) ? 'pl-2 border-l' : ''}`}
603603
style={{ borderTopStyle: 'dashed' }}
604604
>
605-
<span className={`text-[9px] font-bold uppercase tracking-wider block ${subtleText}`}>Source</span>
606-
<span className={`text-[10px] font-medium block ${isLightMode ? 'text-neutral-800' : 'text-neutral-200'}`}>
607-
{pdbMetadata.title}
605+
<span className={`text-[9px] font-bold uppercase tracking-wider block ${subtleText}`}>
606+
{pdbMetadata.cid ? 'Structure' : 'Source'}
608607
</span>
608+
609+
{pdbMetadata.cid ? (
610+
<div className="mt-1 bg-white p-1 rounded-sm flex justify-center border border-neutral-200">
611+
<img
612+
src={`https://pubchem.ncbi.nlm.nih.gov/image/imgsrv.fcgi?cid=${pdbMetadata.cid}&t=l`}
613+
alt="2D Structure"
614+
className="h-20 w-auto object-contain mix-blend-multiply"
615+
/>
616+
</div>
617+
) : (
618+
<span className={`text-[10px] font-medium block ${isLightMode ? 'text-neutral-800' : 'text-neutral-200'}`}>
619+
{pdbMetadata.title}
620+
</span>
621+
)}
609622
</div>
610623
</>
611624
)}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface PDBMetadata {
8484
title?: string;
8585
formula?: string; // Chemical Formula
8686
molecularWeight?: number; // Molecular Weight
87+
cid?: string; // PubChem CID for 2D Image
8788
}
8889

8990
export interface LigandInteraction {

src/utils/pdbUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ export const fetchPubChemMetadata = async (cid: string): Promise<PDBMetadata | n
9696
depositionDate: 'N/A',
9797
title: props.IUPACName || props.Title || `PubChem CID ${cid}`,
9898
formula: props.MolecularFormula,
99-
molecularWeight: props.MolecularWeight ? parseFloat(props.MolecularWeight) : undefined
99+
molecularWeight: props.MolecularWeight ? parseFloat(props.MolecularWeight) : undefined,
100+
cid: cid
100101
};
101102
} catch (e) {
102103
console.warn("PubChem metadata fetch failed", e);

0 commit comments

Comments
 (0)