Prechádzať zdrojové kódy

model format improvements

- add a source format to the mmcif format
- add pdb format
- allow undefined in typeguard .is helpers
Alexander Rose 4 rokov pred
rodič
commit
e28674d0dc

+ 2 - 2
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 {

+ 2 - 2
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 {

+ 2 - 2
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 {

+ 14 - 6
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 } };
     }
 }
 

+ 2 - 2
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 {

+ 2 - 2
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 {

+ 16 - 1
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) {

+ 2 - 2
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 {

+ 2 - 2
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 {

+ 2 - 2
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 {

+ 2 - 2
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 {

+ 2 - 2
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 {

+ 2 - 2
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 {