diff --git a/src/cli/chem-comp-dict/create-ions.ts b/src/cli/chem-comp-dict/create-ions.ts index e7cc6293c969fa14f7f8148727bf585516d8246f..d2c5a27f0ef345824d75a50d0bf30d0919d52d75 100644 --- a/src/cli/chem-comp-dict/create-ions.ts +++ b/src/cli/chem-comp-dict/create-ions.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node /** - * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Josh McMenemy <josh.mcmenemy@gmail.com> */ @@ -14,8 +14,7 @@ const writeFile = util.promisify(fs.writeFile); import { DatabaseCollection } from '../../mol-data/db'; import { CCD_Schema } from '../../mol-io/reader/cif/schema/ccd'; -import { ensureDataAvailable, readCCD } from './create-table'; - +import { ensureDataAvailable, readCCD } from './util'; function extractIonNames(ccd: DatabaseCollection<CCD_Schema>) { const ionNames: string[] = []; @@ -32,12 +31,12 @@ function extractIonNames(ccd: DatabaseCollection<CCD_Schema>) { function writeIonNamesFile(filePath: string, ionNames: string[]) { const output = `/** -* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. -* -* Code-generated ion names params file. Names extracted from CCD components. -* -* @author molstar/chem-comp-dict/create-table cli -*/ + * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * Code-generated ion names params file. Names extracted from CCD components. + * + * @author molstar/chem-comp-dict/create-table cli + */ export const IonNames = new Set(${JSON.stringify(ionNames).replace(/"/g, "'").replace(/,/g, ', ')}); `; diff --git a/src/cli/chem-comp-dict/create-table.ts b/src/cli/chem-comp-dict/create-table.ts index d2518eff0dc3d9c5a8c2ab209eb7a760aa498df3..d21c22639becba400c1f314ea51264c6e4ad9506 100644 --- a/src/cli/chem-comp-dict/create-table.ts +++ b/src/cli/chem-comp-dict/create-table.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node /** - * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ @@ -9,70 +9,16 @@ import * as argparse from 'argparse'; import * as util from 'util'; import * as path from 'path'; import * as fs from 'fs'; -import * as zlib from 'zlib'; -import fetch from 'node-fetch'; require('util.promisify').shim(); -const readFile = util.promisify(fs.readFile); const writeFile = util.promisify(fs.writeFile); -import { Progress } from '../../mol-task'; import { Database, Table, DatabaseCollection } from '../../mol-data/db'; -import { CIF } from '../../mol-io/reader/cif'; -import { CifWriter } from '../../mol-io/writer/cif'; import { CCD_Schema } from '../../mol-io/reader/cif/schema/ccd'; import { SetUtils } from '../../mol-util/set'; import { DefaultMap } from '../../mol-util/map'; import { mmCIF_chemCompBond_schema } from '../../mol-io/reader/cif/schema/mmcif-extras'; import { ccd_chemCompAtom_schema } from '../../mol-io/reader/cif/schema/ccd-extras'; - -export async function ensureAvailable(path: string, url: string, forceDownload = false) { - if (forceDownload || !fs.existsSync(path)) { - console.log(`downloading ${url}...`); - const data = await fetch(url); - if (!fs.existsSync(DATA_DIR)) { - fs.mkdirSync(DATA_DIR); - } - if (url.endsWith('.gz')) { - await writeFile(path, zlib.gunzipSync(await data.buffer())); - } else { - await writeFile(path, await data.text()); - } - console.log(`done downloading ${url}`); - } -} - -export async function ensureDataAvailable(forceDownload = false) { - await ensureAvailable(CCD_PATH, CCD_URL, forceDownload); - await ensureAvailable(PVCD_PATH, PVCD_URL, forceDownload); -} - -export async function readFileAsCollection<S extends Database.Schema>(path: string, schema: S) { - const parsed = await parseCif(await readFile(path, 'utf8')); - return CIF.toDatabaseCollection(schema, parsed.result); -} - -export async function readCCD() { - return readFileAsCollection(CCD_PATH, CCD_Schema); -} - -export async function readPVCD() { - return readFileAsCollection(PVCD_PATH, CCD_Schema); -} - -async function parseCif(data: string | Uint8Array) { - const comp = CIF.parse(data); - console.time('parse cif'); - const parsed = await comp.run(p => console.log(Progress.format(p)), 250); - console.timeEnd('parse cif'); - if (parsed.isError) throw parsed; - return parsed; -} - -export function getEncodedCif(name: string, database: Database<Database.Schema>, binary = false) { - const encoder = CifWriter.createEncoder({ binary, encoderName: 'mol*' }); - CifWriter.Encoder.writeDatabase(encoder, name, database); - return encoder.getData(); -} +import { ensureDataAvailable, getEncodedCif, readCCD, readPVCD } from './util'; type CCB = Table<CCD_Schema['chem_comp_bond']> type CCA = Table<CCD_Schema['chem_comp_atom']> @@ -268,12 +214,6 @@ async function run(out: string, binary = false, forceDownload = false, ccaOut?: const CCB_TABLE_NAME = 'CHEM_COMP_BONDS'; const CCA_TABLE_NAME = 'CHEM_COMP_ATOMS'; -const DATA_DIR = path.join(__dirname, '..', '..', '..', '..', 'build/data'); -const CCD_PATH = path.join(DATA_DIR, 'components.cif'); -const PVCD_PATH = path.join(DATA_DIR, 'aa-variants-v1.cif'); -const CCD_URL = 'http://ftp.wwpdb.org/pub/pdb/data/monomers/components.cif'; -const PVCD_URL = 'http://ftp.wwpdb.org/pub/pdb/data/monomers/aa-variants-v1.cif'; - const parser = new argparse.ArgumentParser({ addHelp: true, description: 'Create a cif file with one big table of all chem_comp_bond entries from the CCD and PVCD.' diff --git a/src/cli/chem-comp-dict/util.ts b/src/cli/chem-comp-dict/util.ts new file mode 100644 index 0000000000000000000000000000000000000000..5de81ee16b1e67812b03af06083b20195e7dc9c9 --- /dev/null +++ b/src/cli/chem-comp-dict/util.ts @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + +import * as util from 'util'; +import * as path from 'path'; +import * as fs from 'fs'; +import * as zlib from 'zlib'; +import fetch from 'node-fetch'; +require('util.promisify').shim(); +const readFile = util.promisify(fs.readFile); +const writeFile = util.promisify(fs.writeFile); + +import { Progress } from '../../mol-task'; +import { Database } from '../../mol-data/db'; +import { CIF } from '../../mol-io/reader/cif'; +import { CifWriter } from '../../mol-io/writer/cif'; +import { CCD_Schema } from '../../mol-io/reader/cif/schema/ccd'; + +export async function ensureAvailable(path: string, url: string, forceDownload = false) { + if (forceDownload || !fs.existsSync(path)) { + console.log(`downloading ${url}...`); + const data = await fetch(url); + if (!fs.existsSync(DATA_DIR)) { + fs.mkdirSync(DATA_DIR); + } + if (url.endsWith('.gz')) { + await writeFile(path, zlib.gunzipSync(await data.buffer())); + } else { + await writeFile(path, await data.text()); + } + console.log(`done downloading ${url}`); + } +} + +export async function ensureDataAvailable(forceDownload = false) { + await ensureAvailable(CCD_PATH, CCD_URL, forceDownload); + await ensureAvailable(PVCD_PATH, PVCD_URL, forceDownload); +} + +export async function readFileAsCollection<S extends Database.Schema>(path: string, schema: S) { + const parsed = await parseCif(await readFile(path, 'utf8')); + return CIF.toDatabaseCollection(schema, parsed.result); +} + +export async function readCCD() { + return readFileAsCollection(CCD_PATH, CCD_Schema); +} + +export async function readPVCD() { + return readFileAsCollection(PVCD_PATH, CCD_Schema); +} + +async function parseCif(data: string | Uint8Array) { + const comp = CIF.parse(data); + console.time('parse cif'); + const parsed = await comp.run(p => console.log(Progress.format(p)), 250); + console.timeEnd('parse cif'); + if (parsed.isError) throw parsed; + return parsed; +} + +export function getEncodedCif(name: string, database: Database<Database.Schema>, binary = false) { + const encoder = CifWriter.createEncoder({ binary, encoderName: 'mol*' }); + CifWriter.Encoder.writeDatabase(encoder, name, database); + return encoder.getData(); +} + +const DATA_DIR = path.join(__dirname, '..', '..', '..', '..', 'build/data'); +const CCD_PATH = path.join(DATA_DIR, 'components.cif'); +const PVCD_PATH = path.join(DATA_DIR, 'aa-variants-v1.cif'); +const CCD_URL = 'http://ftp.wwpdb.org/pub/pdb/data/monomers/components.cif'; +const PVCD_URL = 'http://ftp.wwpdb.org/pub/pdb/data/monomers/aa-variants-v1.cif'; diff --git a/src/cli/lipid-params/index.ts b/src/cli/lipid-params/index.ts index 79be969cd0ad168c7bc27f54ddbdd7288d889a32..d0895a12e7b938bc7753ab5e21cb50b2dbe43790 100644 --- a/src/cli/lipid-params/index.ts +++ b/src/cli/lipid-params/index.ts @@ -54,12 +54,12 @@ async function run(out: string) { if (out) { const output = `/** -* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. -* -* Code-generated lipid params file. Names extracted from Martini FF lipids itp. -* -* @author molstar/lipid-params cli -*/ + * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * Code-generated lipid params file. Names extracted from Martini FF lipids itp. + * + * @author molstar/lipid-params cli + */ export const LipidNames = new Set(${lipidNames.replace(/"/g, "'").replace(/,/g, ', ')}); `; diff --git a/src/mol-model/structure/model/types/ions.ts b/src/mol-model/structure/model/types/ions.ts index 4710a2edbc0832c8bf19f2d863a20bbee1542667..a96bbebd20edeff9dc3d91f4ad201397ffcaa5aa 100644 --- a/src/mol-model/structure/model/types/ions.ts +++ b/src/mol-model/structure/model/types/ions.ts @@ -1,9 +1,9 @@ /** -* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. -* -* Code-generated ion names params file. Names extracted from CCD components. -* -* @author molstar/chem-comp-dict/create-table cli -*/ + * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * Code-generated ion names params file. Names extracted from CCD components. + * + * @author molstar/chem-comp-dict/create-table cli + */ export const IonNames = new Set(['118', '119', '543', '1AL', '1CU', '2FK', '2HP', '2OF', '3CO', '3MT', '3NI', '3OF', '3P8', '4MO', '4PU', '4TI', '6MO', 'ACT', 'AG', 'AL', 'ALF', 'AM', 'ATH', 'AU', 'AU3', 'AUC', 'AZI', 'BA', 'BCT', 'BEF', 'BF4', 'BO4', 'BR', 'BS3', 'BSY', 'CA', 'CAC', 'CD', 'CD1', 'CD3', 'CD5', 'CE', 'CF', 'CHT', 'CL', 'CO', 'CO3', 'CO5', 'CON', 'CR', 'CS', 'CSB', 'CU', 'CU1', 'CU3', 'CUA', 'CUZ', 'CYN', 'DME', 'DMI', 'DSC', 'DTI', 'DY', 'E4N', 'EDR', 'EMC', 'ER3', 'EU', 'EU3', 'F', 'FE', 'FE2', 'FPO', 'GA', 'GD3', 'GEP', 'HAI', 'HG', 'HGC', 'IN', 'IOD', 'IR', 'IR3', 'IRI', 'IUM', 'K', 'KO4', 'LA', 'LCO', 'LCP', 'LI', 'LU', 'MAC', 'MG', 'MH2', 'MH3', 'MLI', 'MMC', 'MN', 'MN3', 'MN5', 'MN6', 'MO1', 'MO2', 'MO3', 'MO4', 'MO5', 'MO6', 'MOO', 'MOS', 'MOW', 'MW1', 'MW2', 'MW3', 'NA', 'NA2', 'NA5', 'NA6', 'NAO', 'NAW', 'NET', 'NH4', 'NI', 'NI1', 'NI2', 'NI3', 'NO2', 'NO3', 'NRU', 'O4M', 'OAA', 'OC1', 'OC2', 'OC3', 'OC4', 'OC5', 'OC6', 'OC7', 'OC8', 'OCL', 'OCM', 'OCN', 'OCO', 'OF1', 'OF2', 'OF3', 'OH', 'OS', 'OS4', 'OXL', 'PB', 'PBM', 'PD', 'PDV', 'PER', 'PI', 'PO3', 'PO4', 'PR', 'PT', 'PT4', 'PTN', 'RB', 'RH3', 'RHD', 'RU', 'SB', 'SCN', 'SE4', 'SEK', 'SM', 'SMO', 'SO3', 'SO4', 'SR', 'T1A', 'TB', 'TBA', 'TCN', 'TEA', 'TH', 'THE', 'TL', 'TMA', 'TRA', 'UNX', 'V', 'VN3', 'VO4', 'W', 'WO5', 'Y1', 'YB', 'YB2', 'YH', 'YT3', 'ZCM', 'ZN', 'ZN2', 'ZN3', 'ZNO', 'ZO3', 'ZR', 'NCO', 'OHX']); diff --git a/src/mol-model/structure/model/types/lipids.ts b/src/mol-model/structure/model/types/lipids.ts index 9814317e4850cfeaf717a36efc1ef8b7c08b9d98..13862a2f098791125365a1929d6c23a48edff884 100644 --- a/src/mol-model/structure/model/types/lipids.ts +++ b/src/mol-model/structure/model/types/lipids.ts @@ -1,9 +1,9 @@ /** -* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. -* -* Code-generated lipid params file. Names extracted from Martini FF lipids itp. -* -* @author molstar/lipid-params cli -*/ + * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * Code-generated lipid params file. Names extracted from Martini FF lipids itp. + * + * @author molstar/lipid-params cli + */ export const LipidNames = new Set(['DAPC', 'DBPC', 'DFPC', 'DGPC', 'DIPC', 'DLPC', 'DNPC', 'DOPC', 'DPPC', 'DRPC', 'DTPC', 'DVPC', 'DXPC', 'DYPC', 'LPPC', 'PAPC', 'PEPC', 'PGPC', 'PIPC', 'POPC', 'PRPC', 'PUPC', 'DAPE', 'DBPE', 'DFPE', 'DGPE', 'DIPE', 'DLPE', 'DNPE', 'DOPE', 'DPPE', 'DRPE', 'DTPE', 'DUPE', 'DVPE', 'DXPE', 'DYPE', 'LPPE', 'PAPE', 'PGPE', 'PIPE', 'POPE', 'PQPE', 'PRPE', 'PUPE', 'DAPS', 'DBPS', 'DFPS', 'DGPS', 'DIPS', 'DLPS', 'DNPS', 'DOPS', 'DPPS', 'DRPS', 'DTPS', 'DUPS', 'DVPS', 'DXPS', 'DYPS', 'LPPS', 'PAPS', 'PGPS', 'PIPS', 'POPS', 'PQPS', 'PRPS', 'PUPS', 'DAPG', 'DBPG', 'DFPG', 'DGPG', 'DIPG', 'DLPG', 'DNPG', 'DOPG', 'DPPG', 'DRPG', 'DTPG', 'DVPG', 'DXPG', 'DYPG', 'LPPG', 'PAPG', 'PGPG', 'PIPG', 'POPG', 'PRPG', 'DAPA', 'DBPA', 'DFPA', 'DGPA', 'DIPA', 'DLPA', 'DNPA', 'DOPA', 'DPPA', 'DRPA', 'DTPA', 'DVPA', 'DXPA', 'DYPA', 'LPPA', 'PAPA', 'PGPA', 'PIPA', 'POPA', 'PRPA', 'PUPA', 'DPP', 'DPPI', 'PAPI', 'PIPI', 'POP', 'POPI', 'PUPI', 'PVP', 'PVPI', 'PADG', 'PIDG', 'PODG', 'PUDG', 'PVDG', 'APC', 'CPC', 'IPC', 'LPC', 'OPC', 'PPC', 'TPC', 'UPC', 'VPC', 'BNSM', 'DBSM', 'DPSM', 'DXSM', 'PGSM', 'PNSM', 'POSM', 'PVSM', 'XNSM', 'DPCE', 'DXCE', 'PNCE', 'XNCE', 'DMPC']);