diff --git a/src/cli/chem-comp-dict/create-ions.ts b/src/cli/chem-comp-dict/create-ions.ts new file mode 100644 index 0000000000000000000000000000000000000000..2de5fd763ddf3c19b117377c9b5f26208c84415a --- /dev/null +++ b/src/cli/chem-comp-dict/create-ions.ts @@ -0,0 +1,74 @@ +#!/usr/bin/env node +/** + * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Josh McMenemy <josh.mcmenemy@gmail.com> + */ + +import * as argparse from 'argparse'; +import * as path from 'path'; +import util from 'util'; +import fs from 'fs'; +require('util.promisify').shim(); +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'; + + +function extractIonNames(ccd: DatabaseCollection<CCD_Schema>) { + const ionNames: string[] = []; + for (const k in ccd) { + const {chem_comp} = ccd[k]; + if (chem_comp.name.value(0).toUpperCase().includes(' ION')) { + ionNames.push(chem_comp.id.value(0)); + } + } + // these are extra ions that don't have ION in their name + ionNames.push('NCO', 'OHX'); + return ionNames; +} + +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 +*/ + +export const IonNames = new Set(${JSON.stringify(ionNames).replace(/"/g, "'").replace(/,/g, ', ')}); +`; + writeFile(filePath, output); +} + +async function run(out: string, forceDownload = false) { + await ensureDataAvailable(forceDownload); + const ccd = await readCCD(); + const ionNames = extractIonNames(ccd); + if (!fs.existsSync(path.dirname(out))) { + fs.mkdirSync(path.dirname(out)); + } + writeIonNamesFile(out, ionNames); +} + +const parser = new argparse.ArgumentParser({ + addHelp: true, + description: 'Extract and save IonNames from CCD.' +}); +parser.addArgument('out', { + help: 'Generated file output path.' +}); +parser.addArgument([ '--forceDownload', '-f' ], { + action: 'storeTrue', + help: 'Force download of CCD and PVCD.' +}); +interface Args { + out: string, + forceDownload?: boolean, +} +const args: Args = parser.parseArgs(); + +run(args.out, args.forceDownload); diff --git a/src/cli/chem-comp-dict/create-table.ts b/src/cli/chem-comp-dict/create-table.ts index f60c4b015c1ddb55258716918577ed6ab09f685d..d2518eff0dc3d9c5a8c2ab209eb7a760aa498df3 100644 --- a/src/cli/chem-comp-dict/create-table.ts +++ b/src/cli/chem-comp-dict/create-table.ts @@ -25,8 +25,8 @@ 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) { - if (FORCE_DOWNLOAD || !fs.existsSync(path)) { +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)) { @@ -41,9 +41,9 @@ export async function ensureAvailable(path: string, url: string) { } } -export async function ensureDataAvailable() { - await ensureAvailable(CCD_PATH, CCD_URL); - await ensureAvailable(PVCD_PATH, PVCD_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) { @@ -243,33 +243,8 @@ function createAtoms(ccd: DatabaseCollection<CCD_Schema>) { ); } -function extractIonNames(ccd: DatabaseCollection<CCD_Schema>) { - const ionNames: string[] = []; - for (const k in ccd) { - const {chem_comp} = ccd[k]; - if (chem_comp.name.value(0).toUpperCase().includes(' ION')) { - ionNames.push(chem_comp.id.value(0)); - } - } - return ionNames; -} - -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 -*/ - -export const IonNames = new Set(${JSON.stringify(ionNames).replace(/"/g, "'").replace(/,/g, ', ')}); -`; - writeFile(filePath, output); -} - -async function run(out: string, binary = false, ionNamesOut?: string, ccaOut?: string) { - await ensureDataAvailable(); +async function run(out: string, binary = false, forceDownload = false, ccaOut?: string) { + await ensureDataAvailable(forceDownload); const ccd = await readCCD(); const pvcd = await readPVCD(); @@ -288,14 +263,6 @@ async function run(out: string, binary = false, ionNamesOut?: string, ccaOut?: s } writeFile(ccaOut, ccaCif); } - - if (!!ionNamesOut) { - const ionNames = extractIonNames(ccd); - if (!fs.existsSync(path.dirname(ionNamesOut))) { - fs.mkdirSync(path.dirname(ionNamesOut)); - } - writeIonNamesFile(ionNamesOut, ionNames); - } } const CCB_TABLE_NAME = 'CHEM_COMP_BONDS'; @@ -322,10 +289,6 @@ parser.addArgument([ '--binary', '-b' ], { action: 'storeTrue', help: 'Output as BinaryCIF.' }); -parser.addArgument([ '--ionNamesOut', '-ino' ], { - help: 'Generated file output path to save extracted ion names.', - required: false -}); parser.addArgument(['--ccaOut', '-a'], { help: 'Optional generated file output path for chem_comp_atom data.', required: false @@ -334,11 +297,8 @@ interface Args { out: string, forceDownload?: boolean, binary?: boolean, - ionNamesOut?: string, ccaOut?: string } const args: Args = parser.parseArgs(); -const FORCE_DOWNLOAD = args.forceDownload; - -run(args.out, args.binary, args.ionNamesOut, args.ccaOut); +run(args.out, args.binary, args.forceDownload, args.ccaOut); diff --git a/src/mol-model/structure/model/types/ions.ts b/src/mol-model/structure/model/types/ions.ts index 62146c4de8c4b8db88d9a8aeec8ab2965a355986..4710a2edbc0832c8bf19f2d863a20bbee1542667 100644 --- a/src/mol-model/structure/model/types/ions.ts +++ b/src/mol-model/structure/model/types/ions.ts @@ -6,4 +6,4 @@ * @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']); +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']);