|
@@ -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;
|
|
|
}
|