Skip to content

Commit c9cbeb0

Browse files
AmirMohammad CheraghaliAmirMohammad Cheraghali
authored andcommitted
feat: properly format ion names using chemical nomenclature (e.g. ZN -> Zn)
1 parent a0272f1 commit c9cbeb0

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/components/Controls.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ import {
3131
Share2
3232
} from 'lucide-react';
3333
import type { RepresentationType, ColoringType, ChainInfo, CustomColorRule, Snapshot, Movie, ColorPalette, PDBMetadata } from '../types';
34+
import { formatChemicalId } from '../utils/pdbUtils';
3435

3536
// Reusable Sidebar Section Component - Defined outside to prevent re-renders losing focus
3637
const SidebarSection = ({ title, icon: Icon, children, isOpen, onToggle, isLightMode }: { title: string, icon: any, children: React.ReactNode, isOpen: boolean, onToggle: () => void, isLightMode: boolean }) => (
3738
<div className={`rounded-xl overflow-hidden transition-colors ${isLightMode
38-
? 'border border-neutral-900 bg-white'
39-
: 'border border-white/10 bg-black/20'
39+
? 'border border-neutral-900 bg-white'
40+
: 'border border-white/10 bg-black/20'
4041
}`}>
4142
<button
4243
onClick={onToggle}
4344
className={`w-full flex items-center justify-between p-3 text-xs font-bold uppercase tracking-wider transition-colors ${isLightMode
44-
? (isOpen ? 'bg-neutral-100 text-black' : 'hover:bg-neutral-50 text-neutral-900 hover:text-black')
45-
: (isOpen ? 'bg-white/5 text-blue-400' : 'hover:bg-white/5 text-neutral-400')
45+
? (isOpen ? 'bg-neutral-100 text-black' : 'hover:bg-neutral-50 text-neutral-900 hover:text-black')
46+
: (isOpen ? 'bg-white/5 text-blue-400' : 'hover:bg-white/5 text-neutral-400')
4647
}`}
4748
>
4849
<div className="flex items-center gap-2">
@@ -757,7 +758,7 @@ export const Controls: React.FC<ControlsProps> = ({
757758
<div className="flex flex-wrap gap-1">
758759
{ligands.map(lig => (
759760
<span key={lig} className="px-1.5 py-0.5 rounded text-[10px] font-mono bg-neutral-200 dark:bg-neutral-700 text-neutral-700 dark:text-neutral-300 border border-neutral-300 dark:border-neutral-600">
760-
{lig}
761+
{formatChemicalId(lig)}
761762
</span>
762763
))}
763764
</div>

src/utils/pdbUtils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,16 @@ export const fetchPDBMetadata = async (pdbId: string): Promise<PDBMetadata | nul
6363
return null;
6464
}
6565
};
66+
67+
/**
68+
* Formats a PDB Ligand ID to Chemical Nomenclature.
69+
* Specifically converts 1-2 letter codes (Ions) to Title Case (ZN -> Zn).
70+
* Keeps 3+ letter codes (Molecules) as Uppercase (HEM -> HEM).
71+
*/
72+
export const formatChemicalId = (id: string): string => {
73+
if (!id) return '';
74+
if (id.length <= 2) {
75+
return id.charAt(0).toUpperCase() + id.slice(1).toLowerCase();
76+
}
77+
return id.toUpperCase();
78+
};

src/utils/pdfGenerator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import jsPDF from 'jspdf';
22
import autoTable from 'jspdf-autotable';
3-
import QRCode from 'qrcode'; // Import QR Code
3+
import QRCode from 'qrcode';
4+
import { formatChemicalId } from './pdbUtils'; // Import QR Code
45
import { getInteractionType } from './interactionUtils';
56
import type { PDBMetadata } from '../types';
67

@@ -723,8 +724,8 @@ const addLigandSection = (doc: jsPDF, interactions: import('../types').LigandInt
723724
doc.setFillColor(243, 244, 246); // Gray-100
724725
doc.rect(margin, y - 5, 180, 8, 'F');
725726

726-
// E.g. "CD #1 (Chain A)", "CD #2 (Chain A)"
727-
doc.text(`${ligand.ligandName} #${count} (Chain ${ligand.ligandChain})`, margin + 3, y + 1);
727+
// E.g. "Cd #1 (Chain A)", "Cd #2 (Chain A)"
728+
doc.text(`${formatChemicalId(ligand.ligandName)} #${count} (Chain ${ligand.ligandChain})`, margin + 3, y + 1);
728729
y += 8;
729730

730731
// Table

0 commit comments

Comments
 (0)