Bladeren bron

OPM support

autin 5 jaren geleden
bovenliggende
commit
ebcfa44f22
3 gewijzigde bestanden met toevoegingen van 30 en 9 verwijderingen
  1. 1 0
      src/extensions/cellpack/data.ts
  2. 24 7
      src/extensions/cellpack/model.ts
  3. 5 2
      src/extensions/cellpack/util.ts

+ 1 - 0
src/extensions/cellpack/data.ts

@@ -65,6 +65,7 @@ export interface Ingredient {
     principalAxis?: Vec3;
     /** offset along membrane */
     offset?: Vec3;
+    ingtype?: string;
 }
 
 export interface IngredientSource {

+ 24 - 7
src/extensions/cellpack/model.ts

@@ -9,7 +9,7 @@ import { PluginContext } from '../../mol-plugin/context';
 import { PluginStateObject as PSO } from '../../mol-plugin-state/objects';
 import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { Ingredient, IngredientSource, CellPacking } from './data';
-import { getFromPdb, getFromCellPackDB, IngredientFiles, parseCif, parsePDBfile, getStructureMean } from './util';
+import { getFromPdb, getFromCellPackDB, IngredientFiles, parseCif, parsePDBfile, getStructureMean, getFromOPM } from './util';
 import { Model, Structure, StructureSymmetry, StructureSelection, QueryContext, Unit } from '../../mol-model/structure';
 import { trajectoryFromMmCIF, MmcifFormat } from '../../mol-model-formats/structure/mmcif';
 import { trajectoryFromPDB } from '../../mol-model-formats/structure/pdb';
@@ -32,7 +32,9 @@ function getCellPackModelUrl(fileName: string, baseUrl: string) {
     return `${baseUrl}/results/${fileName}`;
 }
 
-async function getModel(assetManager: AssetManager, id: string, model_id: number, baseUrl: string, file?: Asset.File) {
+async function getModel(assetManager: AssetManager, id: string, ingredient: Ingredient, baseUrl: string, file?: Asset.File) {
+    const model_id = (ingredient.source.model) ? parseInt(ingredient.source.model) : 0;
+    const surface = (ingredient.ingtype) ? (ingredient.ingtype === 'transmembrane') : false;
     let model: Model;
     let assets: Asset.Wrapper[] = [];
     if (file) {
@@ -55,9 +57,21 @@ async function getModel(assetManager: AssetManager, id: string, model_id: number
             throw new Error(`unsupported file type '${file.name}'`);
         }
     } else if (id.match(/^[1-9][a-zA-Z0-9]{3,3}$/i)) {
-        const { mmcif, asset } = await getFromPdb(id, assetManager);
-        assets.push(asset);
-        model = (await trajectoryFromMmCIF(mmcif).run())[model_id];
+        if (surface){
+            const data = await getFromOPM(id, assetManager);
+            if (data.asset){
+                assets.push(data.asset);
+                model = (await trajectoryFromPDB(data.pdb).run())[model_id];
+            } else {
+                const { mmcif, asset } = await getFromPdb(id, assetManager);
+                assets.push(asset);
+                model = (await trajectoryFromMmCIF(mmcif).run())[model_id];
+            }
+        } else {
+            const { mmcif, asset } = await getFromPdb(id, assetManager);
+            assets.push(asset);
+            model = (await trajectoryFromMmCIF(mmcif).run())[model_id];
+        }
     } else {
         const data = await getFromCellPackDB(id, baseUrl, assetManager);
         assets.push(data.asset);
@@ -288,8 +302,7 @@ async function getIngredientStructure(assetManager: AssetManager, ingredient: In
     }
 
     // model id in case structure is NMR
-    const model_id = (ingredient.source.model) ? parseInt(ingredient.source.model) : 0;
-    const { model, assets } = await getModel(assetManager, source.pdb || name, model_id, baseUrl, file);
+    const { model, assets } = await getModel(assetManager, source.pdb || name, ingredient, baseUrl, file);
     if (!model) return;
 
     let structure: Structure;
@@ -307,10 +320,12 @@ async function getIngredientStructure(assetManager: AssetManager, ingredient: In
         structure = await getStructure(model, source, { assembly: bu });
         // transform with offset and pcp
         let legacy: boolean = true;
+        console.log(name);
         if (ingredient.offset || ingredient.principalAxis){
             legacy = false;
             const structureMean = getStructureMean(structure);
             Vec3.negate(structureMean, structureMean);
+            console.log(structureMean);
             const m1: Mat4 = Mat4.identity();
             Mat4.setTranslation(m1, structureMean);
             structure = Structure.transform(structure, m1);
@@ -320,6 +335,7 @@ async function getIngredientStructure(assetManager: AssetManager, ingredient: In
                     Mat4.setTranslation(m, ingredient.offset);
                     structure = Structure.transform(structure, m);
                 }
+                console.log(ingredient.offset);
             }
             if (ingredient.principalAxis){
                 if (!Vec3.exactEquals(ingredient.principalAxis, Vec3.unitZ)){
@@ -328,6 +344,7 @@ async function getIngredientStructure(assetManager: AssetManager, ingredient: In
                     const m: Mat4 = Mat4.fromQuat(Mat4.zero(), q);
                     structure = Structure.transform(structure, m);
                 }
+                console.log(ingredient.offset);
             }
         }
         structure = getAssembly(getResultTransforms(results, legacy), structure);

+ 5 - 2
src/extensions/cellpack/util.ts

@@ -40,6 +40,11 @@ export async function getFromPdb(pdbId: string, assetManager: AssetManager) {
     return { mmcif: cif.blocks[0], asset };
 }
 
+export async function getFromOPM(pdbId: string, assetManager: AssetManager){
+    const asset = await assetManager.resolve(Asset.getUrlAsset(assetManager, `https://opm-assets.storage.googleapis.com/pdb/${pdbId.toLowerCase()}.pdb`), 'string').run();
+    return { pdb: await parsePDBfile(asset.data, pdbId), asset };
+}
+
 export async function getFromCellPackDB(id: string, baseUrl: string, assetManager: AssetManager) {
     if (id.toLowerCase().endsWith('.cif') || id.toLowerCase().endsWith('.bcif')) {
         const isBinary = id.toLowerCase().endsWith('.bcif');
@@ -53,8 +58,6 @@ export async function getFromCellPackDB(id: string, baseUrl: string, assetManage
 
 export type IngredientFiles = { [name: string]: Asset.File }
 
-//
-
 export function getStructureMean(structure: Structure) {
     let xSum = 0, ySum = 0, zSum = 0;
     for (let i = 0, il = structure.units.length; i < il; ++i) {