Skip to content

Commit 763b757

Browse files
committed
Show ligand name if available
1 parent 649f7f5 commit 763b757

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

frontend/LigandMotifSelection.vue

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,50 @@ function sortResidueStrings(a, b) {
7272
return (posA - 0) - (posB - 0);
7373
}
7474
75+
function unquoteCifString(val = "") {
76+
if (typeof val !== "string" || val === "") {
77+
return val;
78+
}
79+
80+
// semicolon value
81+
if (val.startsWith(";\n") || val === ";") {
82+
return val.replace(/^;\n?/, "").replace(/\n;?\s*$/, "");
83+
}
84+
85+
const first = val[0];
86+
const last = val[val.length - 1];
87+
88+
if ((first === "'" || first === '"') && first === last) {
89+
let inner = val.slice(1, -1);
90+
// replace doubled quote with single quote
91+
const doubled = first + first;
92+
inner = inner.split(doubled).join(first);
93+
return inner;
94+
}
95+
96+
return val;
97+
}
98+
99+
function getNonPolyIdNameLookup(cif) {
100+
const np = cif?.pdbx_entity_nonpoly;
101+
if (!np || !Array.isArray(np.comp_id) || !Array.isArray(np.name)) {
102+
return {};
103+
}
104+
105+
const ids = np.comp_id;
106+
const names = np.name;
107+
const n = Math.min(ids.length, names.length);
108+
109+
const out = {};
110+
for (let i = 0; i < n; i++) {
111+
const id = ids[i];
112+
if (id != null && id !== "") {
113+
out[id] = unquoteCifString(names[i]);
114+
}
115+
}
116+
return out;
117+
}
118+
75119
76120
export default {
77121
name: "LigandMotifSelection",
@@ -130,13 +174,16 @@ export default {
130174
this.loading = true;
131175
const structure = this.queryStructure;
132176
const foundMotifs = [];
177+
const nameLookup = getNonPolyIdNameLookup(structure.extraData?.cif);
133178
134179
try {
135180
structure.eachResidue(res => {
136181
if (res.isPolymer() || res.isWater()) return;
137182
138183
const chain = res.chainname || "_";
139-
const ligID = `${res.resname} ${res.resno}:${chain}`;
184+
const ligID = res.resname in nameLookup
185+
? `${res.resname} ${nameLookup[res.resname]} ${chain}${res.resno}`
186+
: `${res.resname} ${chain}${res.resno}`;
140187
141188
const ligAtomIndices = [];
142189
res.eachAtom(a => ligAtomIndices.push(a.index));

0 commit comments

Comments
 (0)