Browse Source

propagate chem_comp_atom data

JonStargaryen 4 years ago
parent
commit
6d9a09620c

+ 28 - 2
src/servers/model/properties/providers/wwpdb.ts

@@ -11,12 +11,14 @@ import { CIF } from '../../../../mol-io/reader/cif';
 import { getParam } from '../../../common/util';
 import { mmCIF_Database, mmCIF_Schema } from '../../../../mol-io/reader/cif/schema/mmcif';
 import { ComponentBond } from '../../../../mol-model-formats/structure/property/bonds/comp';
+import { ComponentAtom } from '../../../../mol-model-formats/structure/property/bonds/atom';
+import { CCD_Database, CCD_Schema } from '../../../../mol-io/reader/cif/schema/ccd';
 
 require('util.promisify').shim();
 const readFile = util.promisify(fs.readFile);
 
 export const wwPDB_chemCompBond: AttachModelProperty = async ({ model, params }) => {
-    const table = await getChemCompBondTable(getTablePath(params));
+    const table = await getChemCompBondTable(getBondTablePath(params));
     const data = ComponentBond.chemCompBondFromTable(model, table);
     const entries = ComponentBond.getEntriesFromChemCompBond(data);
     return ComponentBond.Provider.set(model, { entries, data });
@@ -37,8 +39,32 @@ async function getChemCompBondTable(path: string): Promise<mmCIF_Database['chem_
     return chemCompBondTable;
 }
 
-function getTablePath(params: any) {
+function getBondTablePath(params: any) {
     const path = getParam<string>(params, 'wwPDB', 'chemCompBondTablePath');
     if (!path) throw new Error(`wwPDB 'chemCompBondTablePath' not set!`);
     return path;
+}
+
+export const wwPDB_chemCompAtom: AttachModelProperty = async ({ model, params }) => {
+    const table = await getChemCompAtomTable(getAtomTablePath(params));
+    const data = ComponentAtom.chemCompAtomFromTable(model, table);
+    const entries = ComponentAtom.getEntriesFromChemCompAtom(data);
+    return ComponentAtom.Provider.set(model, { entries, data });
+};
+
+let chemCompAtomTable: CCD_Database['chem_comp_atom'];
+async function getChemCompAtomTable(path: string): Promise<CCD_Database['chem_comp_atom']> {
+    if (!chemCompAtomTable) {
+        const parsed = await CIF.parse(await read(path)).run();
+        if (parsed.isError) throw new Error(parsed.toString());
+        const table = CIF.toDatabase(CCD_Schema, parsed.result.blocks[0]);
+        chemCompAtomTable = table.chem_comp_atom;
+    }
+    return chemCompAtomTable;
+}
+
+function getAtomTablePath(params: any) {
+    const path = getParam<string>(params, 'wwPDB', 'chemCompAtomTablePath');
+    if (!path) throw new Error(`wwPDB 'chemCompAtomTablePath' not set!`);
+    return path;
 }

+ 3 - 2
src/servers/model/properties/wwpdb.ts

@@ -5,12 +5,13 @@
  */
 
 import { AttachModelProperties } from '../property-provider';
-import { wwPDB_chemCompBond } from './providers/wwpdb';
+import { wwPDB_chemCompBond, wwPDB_chemCompAtom } from './providers/wwpdb';
 
 export const attachModelProperties: AttachModelProperties = (args) => {
     // return a list of promises that start attaching the props in parallel
     // (if there are downloads etc.)
     return [
-        wwPDB_chemCompBond(args)
+        wwPDB_chemCompBond(args),
+        wwPDB_chemCompAtom(args)
     ];
 };

+ 4 - 3
src/servers/model/server/query.ts

@@ -229,13 +229,14 @@ async function resolveJobEntry(entry: JobEntry, structure: StructureWrapper, enc
         encoder.writeCategory(_model_server_params, entry);
 
         if (entry.queryDefinition.niceName === 'Ligand') {
-            if (encoder instanceof MolEncoder || encoder instanceof Mol2Encoder) {
+            if (encoder instanceof MolEncoder) {
                 encoder.setComponentAtomData(ComponentAtom.Provider.get(structure.models[0])!);
+            }
+            if (encoder instanceof MolEncoder || encoder instanceof Mol2Encoder) {
                 encoder.setComponentBondData(ComponentBond.Provider.get(structure.models[0])!);
             }
-        } else {
-            // TODO propagate data for cif/bcif as well
         }
+        // TODO propagate data for cif/bcif as well?
 
         if (!entry.copyAllCategories && entry.queryDefinition.filter) encoder.setFilter(entry.queryDefinition.filter);
         if (result.length > 0) encode_mmCIF_categories(encoder, result, { copyAllCategories: entry.copyAllCategories });