Skip to content
Snippets Groups Projects
Commit 11d5e301 authored by David Sehnal's avatar David Sehnal
Browse files

xtc format support

+ build tweaks
parent 2797b451
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { Task } from '../../mol-task';
import { XtcFile } from '../../mol-io/reader/xtc/parser';
import { Coordinates, Frame, Time } from '../../mol-model/structure/coordinates';
import { Cell } from '../../mol-math/geometry/spacegroup/cell';
export function coordinatesFromXtc(file: XtcFile): Task<Coordinates> {
return Task.create('Parse XTC', async ctx => {
await ctx.update('Converting to coordinates');
const deltaTime = Time(file.deltaTime, 'step');
const offsetTime = Time(file.timeOffset, deltaTime.unit);
const frames: Frame[] = [];
for (let i = 0, il = file.frames.length; i < il; ++i) {
frames.push({
elementCount: file.frames[i].count,
// TODO:
cell: Cell.empty(),
x: file.frames[i].x,
y: file.frames[i].y,
z: file.frames[i].z,
time: Time(offsetTime.value + deltaTime.value * i, deltaTime.unit)
});
}
return Coordinates.create(frames, deltaTime, offsetTime);
});
}
...@@ -41,9 +41,24 @@ export const DcdProvider = DataFormatProvider({ ...@@ -41,9 +41,24 @@ export const DcdProvider = DataFormatProvider({
} }
}); });
export const XtcProvider = DataFormatProvider({
label: 'XTC',
description: 'XTC',
category: Category,
binaryExtensions: ['xtc'],
parse: (plugin, data) => {
const coordinates = plugin.state.data.build()
.to(data)
.apply(StateTransforms.Model.CoordinatesFromXtc);
return coordinates.commit();
}
});
export const BuiltInStructureFormats = [ export const BuiltInStructureFormats = [
['psf', PsfProvider] as const, ['psf', PsfProvider] as const,
['dcd', DcdProvider] as const, ['dcd', DcdProvider] as const,
['xtc', XtcProvider] as const,
] as const; ] as const;
export type BuildInStructureFormat = (typeof BuiltInStructureFormats)[number][0] export type BuildInStructureFormat = (typeof BuiltInStructureFormats)[number][0]
\ No newline at end of file
...@@ -37,8 +37,11 @@ import { trajectoryFromCifCore } from '../../mol-model-formats/structure/cif-cor ...@@ -37,8 +37,11 @@ import { trajectoryFromCifCore } from '../../mol-model-formats/structure/cif-cor
import { trajectoryFromCube } from '../../mol-model-formats/structure/cube'; import { trajectoryFromCube } from '../../mol-model-formats/structure/cube';
import { parseMol2 } from '../../mol-io/reader/mol2/parser'; import { parseMol2 } from '../../mol-io/reader/mol2/parser';
import { trajectoryFromMol2 } from '../../mol-model-formats/structure/mol2'; import { trajectoryFromMol2 } from '../../mol-model-formats/structure/mol2';
import { parseXtc } from '../../mol-io/reader/xtc/parser';
import { coordinatesFromXtc } from '../../mol-model-formats/structure/xtc';
export { CoordinatesFromDcd }; export { CoordinatesFromDcd };
export { CoordinatesFromXtc };
export { TopologyFromPsf }; export { TopologyFromPsf };
export { TrajectoryFromModelAndCoordinates }; export { TrajectoryFromModelAndCoordinates };
export { TrajectoryFromBlob }; export { TrajectoryFromBlob };
...@@ -81,6 +84,23 @@ const CoordinatesFromDcd = PluginStateTransform.BuiltIn({ ...@@ -81,6 +84,23 @@ const CoordinatesFromDcd = PluginStateTransform.BuiltIn({
} }
}); });
type CoordinatesFromXtc = typeof CoordinatesFromDcd
const CoordinatesFromXtc = PluginStateTransform.BuiltIn({
name: 'coordinates-from-xtc',
display: { name: 'Parse XTC', description: 'Parse XTC binary data.' },
from: [SO.Data.Binary],
to: SO.Molecule.Coordinates
})({
apply({ a }) {
return Task.create('Parse XTC', async ctx => {
const parsed = await parseXtc(a.data).runInContext(ctx);
if (parsed.isError) throw new Error(parsed.message);
const coordinates = await coordinatesFromXtc(parsed.result).runInContext(ctx);
return new SO.Molecule.Coordinates(coordinates, { label: a.label, description: 'Coordinates' });
});
}
});
type TopologyFromPsf = typeof TopologyFromPsf type TopologyFromPsf = typeof TopologyFromPsf
const TopologyFromPsf = PluginStateTransform.BuiltIn({ const TopologyFromPsf = PluginStateTransform.BuiltIn({
name: 'topology-from-psf', name: 'topology-from-psf',
......
...@@ -32,13 +32,14 @@ const sharedConfig = { ...@@ -32,13 +32,14 @@ const sharedConfig = {
], ],
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env.DEBUG': JSON.stringify(process.env.DEBUG) 'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
'__MOLSTAR_DEBUG_TIMESTAMP__': webpack.DefinePlugin.runtimeValue(() => `${new Date().valueOf()}`, true)
}), }),
new MiniCssExtractPlugin({ filename: 'molstar.css', }), new MiniCssExtractPlugin({ filename: 'molstar.css', }),
new VersionFile({ new VersionFile({
extras: { timestamp: `${new Date().valueOf()}` }, extras: { timestamp: `${new Date().valueOf()}` },
packageFile: path.resolve(__dirname, 'package.json'), packageFile: path.resolve(__dirname, 'package.json'),
templateString: `export const PLUGIN_VERSION = '<%= package.version %>';\nexport const PLUGIN_VERSION_DATE = new Date(<%= extras.timestamp %>);`, templateString: `export const PLUGIN_VERSION = '<%= package.version %>';\nexport const PLUGIN_VERSION_DATE = new Date(typeof __MOLSTAR_DEBUG_TIMESTAMP__ !== 'undefined' ? __MOLSTAR_DEBUG_TIMESTAMP__ : <%= extras.timestamp %>);`,
outputFile: path.resolve(__dirname, 'lib/mol-plugin/version.js') outputFile: path.resolve(__dirname, 'lib/mol-plugin/version.js')
}) })
], ],
......
const { createApp, createExample, createBrowserTest } = require('./webpack.config.common.js'); const { createApp, createExample, createBrowserTest } = require('./webpack.config.common.js');
const apps = ['viewer'];
const examples = ['proteopedia-wrapper', 'basic-wrapper', 'lighting']; const examples = ['proteopedia-wrapper', 'basic-wrapper', 'lighting'];
const tests = [ const tests = [
'font-atlas', 'font-atlas',
...@@ -10,7 +9,7 @@ const tests = [ ...@@ -10,7 +9,7 @@ const tests = [
]; ];
module.exports = [ module.exports = [
...apps.map(createApp), createApp('viewer', 'molstar'),
...examples.map(createExample), ...examples.map(createExample),
...tests.map(createBrowserTest) ...tests.map(createBrowserTest)
] ]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment