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

fix bond ordering when creating structure from Topology

parent aca49b9b
No related branches found
No related tags found
No related merge requests found
...@@ -120,16 +120,26 @@ export namespace Model { ...@@ -120,16 +120,26 @@ export namespace Model {
return _trajectoryFromModelAndCoordinates(model, coordinates).trajectory; return _trajectoryFromModelAndCoordinates(model, coordinates).trajectory;
} }
function invertIndex(xs: ArrayLike<number>) {
const ret = new Int32Array(xs.length);
for (let i = 0, _i = xs.length; i < _i; i++) {
ret[xs[i]] = i;
}
return ret;
}
export function trajectoryFromTopologyAndCoordinates(topology: Topology, coordinates: Coordinates): Task<Trajectory> { export function trajectoryFromTopologyAndCoordinates(topology: Topology, coordinates: Coordinates): Task<Trajectory> {
return Task.create('Create Trajectory', async ctx => { return Task.create('Create Trajectory', async ctx => {
const model = (await createModels(topology.basic, topology.sourceData, ctx))[0]; const model = (await createModels(topology.basic, topology.sourceData, ctx))[0];
if (!model) throw new Error('found no model'); if (!model) throw new Error('found no model');
const { trajectory, srcIndexArray } = _trajectoryFromModelAndCoordinates(model, coordinates); const { trajectory, srcIndexArray } = _trajectoryFromModelAndCoordinates(model, coordinates);
// TODO: cache the inverted index somewhere?
const invertedIndex = srcIndexArray ? invertIndex(srcIndexArray) : void 0;
const pairs = srcIndexArray const pairs = srcIndexArray
? { ? {
indexA: Column.ofIntArray(Column.mapToArray(topology.bonds.indexA, i => srcIndexArray[i], Int32Array)), indexA: Column.ofIntArray(Column.mapToArray(topology.bonds.indexA, i => invertedIndex![i], Int32Array)),
indexB: Column.ofIntArray(Column.mapToArray(topology.bonds.indexB, i => srcIndexArray[i], Int32Array)), indexB: Column.ofIntArray(Column.mapToArray(topology.bonds.indexB, i => invertedIndex![i], Int32Array)),
order: topology.bonds.order order: topology.bonds.order
} }
: topology.bonds; : topology.bonds;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment