Skip to content

Commit

Permalink
added mdsrv datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
arose committed Jul 8, 2017
1 parent 2b59cdd commit 0d45c92
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ build/
node_modules/

npm-debug.log

*.offsets
54 changes: 34 additions & 20 deletions examples/webapp.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,46 @@
<script src="js/plugins.js"></script>

<script>
NGL.cssDirectory = "css/";
NGL.documentationUrl = "../build/docs/";
NGL.examplesListUrl = "../build/scriptsList.json";
NGL.examplesScriptUrl = "./scripts/";
NGL.cssDirectory = "css/"
NGL.documentationUrl = "../build/docs/"
NGL.examplesListUrl = "../build/scriptsList.json"
NGL.examplesScriptUrl = "./scripts/"

// Datasources
NGL.DatasourceRegistry.add(
"data", new NGL.StaticDatasource("../data/")
);
NGL.DatasourceRegistry.add( "data", new NGL.StaticDatasource("../data/"))
var mdsrv = NGL.getQuery("mdsrv")
if (mdsrv) {
NGL.DatasourceRegistry.add( "file", new NGL.MdsrvDatasource(mdsrv))
NGL.DatasourceRegistry.listing = NGL.DatasourceRegistry.get("file")
NGL.DatasourceRegistry.trajectory = NGL.DatasourceRegistry.get("file")
}

// Plugins
NGL.PluginRegistry.add(
"apbs", "plugins/apbs.plugin"
);
NGL.PluginRegistry.add("apbs", "plugins/apbs.plugin")

var stage;
var stage
document.addEventListener("DOMContentLoaded", function () {
stage = new NGL.Stage();
NGL.StageWidget(stage);
var load = NGL.getQuery("load");
if (load) stage.loadFile(load, {defaultRepresentation: true});
var script = NGL.getQuery("script");
if (script) stage.loadFile("./scripts/" + script + ".js");
var plugin = NGL.getQuery("plugin");
if (plugin) NGL.PluginRegistry.load(plugin, stage);
});
stage = new NGL.Stage()
NGL.StageWidget(stage)

var load = NGL.getQuery("load")
if (load) stage.loadFile(load, {defaultRepresentation: true})

var script = NGL.getQuery("script")
if (script) stage.loadFile("./scripts/" + script + ".js")
var plugin = NGL.getQuery("plugin")
if (plugin) NGL.PluginRegistry.load(plugin, stage)

var struc = NGL.getQuery( "struc" )
var traj = NGL.getQuery( "traj" )
if (struc) {
stage.loadFile(struc, {
defaultRepresentation: true
}).then( function(o) {
if (traj) o.addTrajectory(traj)
})
}
})
</script>
</body>
</html>
56 changes: 56 additions & 0 deletions src/datasource/mdsrv-datasource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @file MDsrv Datasource
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/

import { getFileInfo } from '../utils.js'
import { autoLoad } from '../loader/loader-utils.js'
import Datasource from './datasource.js'

class MdsrvDatasource extends Datasource {
constructor (baseUrl) {
super()
this.baseUrl = baseUrl || ''
}

getListing (path) {
path = path || ''
let url = this.baseUrl + 'dir/' + path
if (url[url.length - 1] !== '/') url += '/'
return autoLoad(url, {
ext: 'json'
}).then(function (jsonData) {
return {
path: path,
data: jsonData.data
}
})
}

getUrl (src) {
const info = getFileInfo(src)
return this.baseUrl + 'file/' + info.path
}

getNumframesUrl (src) {
const info = getFileInfo(src)
return this.baseUrl + 'traj/numframes/' + info.path
}

getFrameUrl (src, frameIndex) {
const info = getFileInfo(src)
return this.baseUrl + 'traj/frame/' + frameIndex + '/' + info.path
}

getFrameParams (src, atomIndices) {
return 'atomIndices=' + atomIndices.join(';')
}

getPathUrl (src, atomIndex) {
const info = getFileInfo(src)
return this.baseUrl + 'traj/path/' + atomIndex + '/' + info.path
}
}

export default MdsrvDatasource
2 changes: 2 additions & 0 deletions src/ngl.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ import './datasource/rcsb-datasource.js'
import './datasource/pubchem-datasource.js'
import './datasource/passthrough-datasource.js'
import StaticDatasource from './datasource/static-datasource.js'
import MdsrvDatasource from './datasource/mdsrv-datasource.js'

//

Expand Down Expand Up @@ -189,6 +190,7 @@ export {
setDebug,
DatasourceRegistry,
StaticDatasource,
MdsrvDatasource,
ParserRegistry,
autoLoad,
RepresentationRegistry,
Expand Down

0 comments on commit 0d45c92

Please sign in to comment.