From e28674d0dc65eb88aeba806cbf326376a203e667 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Wed, 3 Feb 2021 19:36:01 -0800 Subject: [PATCH] model format improvements - add a source format to the mmcif format - add pdb format - allow undefined in typeguard .is helpers --- src/mol-model-formats/structure/cif-core.ts | 4 ++-- src/mol-model-formats/structure/cube.ts | 4 ++-- src/mol-model-formats/structure/gro.ts | 4 ++-- src/mol-model-formats/structure/mmcif.ts | 20 +++++++++++++------ src/mol-model-formats/structure/mol.ts | 4 ++-- src/mol-model-formats/structure/mol2.ts | 4 ++-- src/mol-model-formats/structure/pdb.ts | 17 +++++++++++++++- src/mol-model-formats/structure/psf.ts | 4 ++-- src/mol-model-formats/volume/ccp4.ts | 4 ++-- src/mol-model-formats/volume/cube.ts | 4 ++-- .../volume/density-server.ts | 4 ++-- src/mol-model-formats/volume/dsn6.ts | 4 ++-- src/mol-model-formats/volume/dx.ts | 4 ++-- 13 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/mol-model-formats/structure/cif-core.ts b/src/mol-model-formats/structure/cif-core.ts index e3e3bd296..75af4d45f 100644 --- a/src/mol-model-formats/structure/cif-core.ts +++ b/src/mol-model-formats/structure/cif-core.ts @@ -251,8 +251,8 @@ type CifCoreFormat = ModelFormat<CifCoreFormat.Data> namespace CifCoreFormat { export type Data = { db: CifCore_Database, frame: CifFrame } - export function is(x: ModelFormat): x is CifCoreFormat { - return x.kind === 'cifCore'; + export function is(x?: ModelFormat): x is CifCoreFormat { + return x?.kind === 'cifCore'; } export function fromFrame(frame: CifFrame, db?: CifCore_Database): CifCoreFormat { diff --git a/src/mol-model-formats/structure/cube.ts b/src/mol-model-formats/structure/cube.ts index 9983693f0..1c04f685d 100644 --- a/src/mol-model-formats/structure/cube.ts +++ b/src/mol-model-formats/structure/cube.ts @@ -69,8 +69,8 @@ export { CubeFormat }; type CubeFormat = ModelFormat<CubeFile> namespace MolFormat { - export function is(x: ModelFormat): x is CubeFormat { - return x.kind === 'cube'; + export function is(x?: ModelFormat): x is CubeFormat { + return x?.kind === 'cube'; } export function create(cube: CubeFile): CubeFormat { diff --git a/src/mol-model-formats/structure/gro.ts b/src/mol-model-formats/structure/gro.ts index af13e6c01..33f0efac5 100644 --- a/src/mol-model-formats/structure/gro.ts +++ b/src/mol-model-formats/structure/gro.ts @@ -106,8 +106,8 @@ export { GroFormat }; type GroFormat = ModelFormat<GroFile> namespace GroFormat { - export function is(x: ModelFormat): x is GroFormat { - return x.kind === 'gro'; + export function is(x?: ModelFormat): x is GroFormat { + return x?.kind === 'gro'; } export function fromGro(gro: GroFile): GroFormat { diff --git a/src/mol-model-formats/structure/mmcif.ts b/src/mol-model-formats/structure/mmcif.ts index 67caefba3..9ccb7d28d 100644 --- a/src/mol-model-formats/structure/mmcif.ts +++ b/src/mol-model-formats/structure/mmcif.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> @@ -79,14 +79,22 @@ export { MmcifFormat }; type MmcifFormat = ModelFormat<MmcifFormat.Data> namespace MmcifFormat { - export type Data = { db: mmCIF_Database, frame: CifFrame } - export function is(x: ModelFormat): x is MmcifFormat { - return x.kind === 'mmCIF'; + export type Data = { + db: mmCIF_Database, + frame: CifFrame, + /** + * Original source format. Some formats, including PDB, are converted + * to mmCIF before further processing. + */ + source?: ModelFormat + } + export function is(x?: ModelFormat): x is MmcifFormat { + return x?.kind === 'mmCIF'; } - export function fromFrame(frame: CifFrame, db?: mmCIF_Database): MmcifFormat { + export function fromFrame(frame: CifFrame, db?: mmCIF_Database, source?: ModelFormat): MmcifFormat { if (!db) db = CIF.schema.mmCIF(frame); - return { kind: 'mmCIF', name: db._name, data: { db, frame } }; + return { kind: 'mmCIF', name: db._name, data: { db, frame, source } }; } } diff --git a/src/mol-model-formats/structure/mol.ts b/src/mol-model-formats/structure/mol.ts index 51f45c0d0..fb66c34e8 100644 --- a/src/mol-model-formats/structure/mol.ts +++ b/src/mol-model-formats/structure/mol.ts @@ -81,8 +81,8 @@ export { MolFormat }; type MolFormat = ModelFormat<MolFile> namespace MolFormat { - export function is(x: ModelFormat): x is MolFormat { - return x.kind === 'mol'; + export function is(x?: ModelFormat): x is MolFormat { + return x?.kind === 'mol'; } export function create(mol: MolFile): MolFormat { diff --git a/src/mol-model-formats/structure/mol2.ts b/src/mol-model-formats/structure/mol2.ts index 43772c8ad..ec9565fe0 100644 --- a/src/mol-model-formats/structure/mol2.ts +++ b/src/mol-model-formats/structure/mol2.ts @@ -99,8 +99,8 @@ export { Mol2Format }; type Mol2Format = ModelFormat<Mol2File> namespace Mol2Format { - export function is(x: ModelFormat): x is Mol2Format { - return x.kind === 'mol2'; + export function is(x?: ModelFormat): x is Mol2Format { + return x?.kind === 'mol2'; } export function create(mol2: Mol2File): Mol2Format { diff --git a/src/mol-model-formats/structure/pdb.ts b/src/mol-model-formats/structure/pdb.ts index 87c6006e9..8f794c328 100644 --- a/src/mol-model-formats/structure/pdb.ts +++ b/src/mol-model-formats/structure/pdb.ts @@ -13,12 +13,27 @@ import { createModels } from './basic/parser'; import { Column } from '../../mol-data/db'; import { AtomPartialCharge } from './property/partial-charge'; import { Trajectory } from '../../mol-model/structure'; +import { ModelFormat } from '../format'; + +export { PdbFormat }; + +type PdbFormat = ModelFormat<PdbFile> + +namespace PdbFormat { + export function is(x?: ModelFormat): x is PdbFormat { + return x?.kind === 'pdb'; + } + + export function create(pdb: PdbFile): PdbFormat { + return { kind: 'pdb', name: pdb.id || '', data: pdb }; + } +} export function trajectoryFromPDB(pdb: PdbFile): Task<Trajectory> { return Task.create('Parse PDB', async ctx => { await ctx.update('Converting to mmCIF'); const cif = await pdbToMmCif(pdb); - const format = MmcifFormat.fromFrame(cif); + const format = MmcifFormat.fromFrame(cif, undefined, PdbFormat.create(pdb)); const models = await createModels(format.data.db, format, ctx); const partial_charge = cif.categories['atom_site']?.getField('partial_charge'); if (partial_charge) { diff --git a/src/mol-model-formats/structure/psf.ts b/src/mol-model-formats/structure/psf.ts index 344795f79..362cf9f22 100644 --- a/src/mol-model-formats/structure/psf.ts +++ b/src/mol-model-formats/structure/psf.ts @@ -103,8 +103,8 @@ export { PsfFormat }; type PsfFormat = ModelFormat<PsfFile> namespace PsfFormat { - export function is(x: ModelFormat): x is PsfFormat { - return x.kind === 'psf'; + export function is(x?: ModelFormat): x is PsfFormat { + return x?.kind === 'psf'; } export function fromPsf(psf: PsfFile): PsfFormat { diff --git a/src/mol-model-formats/volume/ccp4.ts b/src/mol-model-formats/volume/ccp4.ts index c86cb08b1..753713c95 100644 --- a/src/mol-model-formats/volume/ccp4.ts +++ b/src/mol-model-formats/volume/ccp4.ts @@ -98,8 +98,8 @@ export { Ccp4Format }; type Ccp4Format = ModelFormat<Ccp4File> namespace Ccp4Format { - export function is(x: ModelFormat): x is Ccp4Format { - return x.kind === 'ccp4'; + export function is(x?: ModelFormat): x is Ccp4Format { + return x?.kind === 'ccp4'; } export function create(ccp4: Ccp4File): Ccp4Format { diff --git a/src/mol-model-formats/volume/cube.ts b/src/mol-model-formats/volume/cube.ts index 224812fd5..6ff8ea4c0 100644 --- a/src/mol-model-formats/volume/cube.ts +++ b/src/mol-model-formats/volume/cube.ts @@ -71,8 +71,8 @@ export { CubeFormat }; type CubeFormat = ModelFormat<CubeFile> namespace CubeFormat { - export function is(x: ModelFormat): x is CubeFormat { - return x.kind === 'cube'; + export function is(x?: ModelFormat): x is CubeFormat { + return x?.kind === 'cube'; } export function create(cube: CubeFile): CubeFormat { diff --git a/src/mol-model-formats/volume/density-server.ts b/src/mol-model-formats/volume/density-server.ts index 5e8a3ab5d..65b88fb50 100644 --- a/src/mol-model-formats/volume/density-server.ts +++ b/src/mol-model-formats/volume/density-server.ts @@ -62,8 +62,8 @@ export { DscifFormat }; type DscifFormat = ModelFormat<DensityServer_Data_Database> namespace DscifFormat { - export function is(x: ModelFormat): x is DscifFormat { - return x.kind === 'dscif'; + export function is(x?: ModelFormat): x is DscifFormat { + return x?.kind === 'dscif'; } export function create(dscif: DensityServer_Data_Database): DscifFormat { diff --git a/src/mol-model-formats/volume/dsn6.ts b/src/mol-model-formats/volume/dsn6.ts index 75196b04a..ae1973438 100644 --- a/src/mol-model-formats/volume/dsn6.ts +++ b/src/mol-model-formats/volume/dsn6.ts @@ -60,8 +60,8 @@ export { Dsn6Format }; type Dsn6Format = ModelFormat<Dsn6File> namespace Dsn6Format { - export function is(x: ModelFormat): x is Dsn6Format { - return x.kind === 'dsn6'; + export function is(x?: ModelFormat): x is Dsn6Format { + return x?.kind === 'dsn6'; } export function create(dsn6: Dsn6File): Dsn6Format { diff --git a/src/mol-model-formats/volume/dx.ts b/src/mol-model-formats/volume/dx.ts index e850511c4..d27e7c94c 100644 --- a/src/mol-model-formats/volume/dx.ts +++ b/src/mol-model-formats/volume/dx.ts @@ -48,8 +48,8 @@ export { DxFormat }; type DxFormat = ModelFormat<DxFile> namespace DxFormat { - export function is(x: ModelFormat): x is DxFormat { - return x.kind === 'dx'; + export function is(x?: ModelFormat): x is DxFormat { + return x?.kind === 'dx'; } export function create(dx: DxFile): DxFormat { -- GitLab