From 0a30ed45f9381c57ca350da9edb438f2f9265d53 Mon Sep 17 00:00:00 2001 From: McMenemy <josh.mcmenemy@gmail.com> Date: Fri, 25 Sep 2020 19:17:42 -0700 Subject: [PATCH] first pass working extracting ion names --- src/cli/chem-comp-dict/create-table.ts | 62 +++++++++++++++++++++----- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/src/cli/chem-comp-dict/create-table.ts b/src/cli/chem-comp-dict/create-table.ts index 0f564ce68..d714a69e6 100644 --- a/src/cli/chem-comp-dict/create-table.ts +++ b/src/cli/chem-comp-dict/create-table.ts @@ -136,11 +136,11 @@ function checkAddingBondsFromPVCD(pvcd: DatabaseCollection<CCD_Schema>) { } } -async function createBonds(atomsRequested: boolean) { - await ensureDataAvailable(); - const ccd = await readCCD(); - const pvcd = await readPVCD(); - +async function createBonds( + ccd: DatabaseCollection<CCD_Schema>, + pvcd: DatabaseCollection<CCD_Schema>, + atomsRequested: boolean +) { const ccbSet = new Set<string>(); const comp_id: string[] = []; @@ -243,8 +243,37 @@ function createAtoms(ccd: DatabaseCollection<CCD_Schema>) { ); } -async function run(out: string, binary = false, ccaOut?: string) { - const { bonds, atoms } = await createBonds(!!ccaOut); +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(); + const ccd = await readCCD(); + const pvcd = await readPVCD(); + + const { bonds, atoms } = await createBonds(ccd, pvcd, !!ccaOut); const ccbCif = getEncodedCif(CCB_TABLE_NAME, bonds, binary); if (!fs.existsSync(path.dirname(out))) { @@ -259,6 +288,14 @@ async function run(out: string, binary = false, ccaOut?: string) { } 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'; @@ -285,18 +322,23 @@ parser.addArgument([ '--binary', '-b' ], { action: 'storeTrue', help: 'Output as BinaryCIF.' }); +parser.addArgument([ '--ionNamesOut', '-ino' ], { + help: 'Extract and store ion names.', + required: false +}); parser.addArgument(['--ccaOut', '-a'], { help: 'Optional generated file output path for chem_comp_atom data.', required: false }); interface Args { - out: string - forceDownload?: boolean + 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.ccaOut); +run(args.out, args.binary, args.ionNamesOut, args.ccaOut); -- GitLab