Skip to content

Commit

Permalink
fix par file visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikPoppleton committed Jun 11, 2024
1 parent ebaa59c commit 112feb5
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 11 deletions.
14 changes: 11 additions & 3 deletions dist/file_handling/aux_readers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ function readTraj(trajFile, system) {
function readJson(jsonFile, system) {
return parseFileWith(jsonFile, parseJson, [system]);
}
function readParFile(parFile, system) {
return parseFileWith(parFile, parsePar, [system]);
}
// Creates color overlays
function makeLut(data, key, system) {
let arr = data[key];
Expand Down Expand Up @@ -204,8 +207,8 @@ function readSelectFile(reader) {
api.selectElementIDs(ids, true);
}
//reads in an anm parameter file and associates it with the last loaded system.
function readParFile(system, reader) {
let lines = reader.result.split(/[\n]+/g);
function parsePar(lines, system) {
lines = lines.split(/[\n]+/g);
//remove the header
lines = lines.slice(1);
const size = lines.length;
Expand All @@ -216,6 +219,12 @@ function readParFile(system, reader) {
let l = lines[i].split(/\s+/);
//extract values
const p = parseInt(l[0]), q = parseInt(l[1]), eqDist = parseFloat(l[2]), type = l[3], strength = parseFloat(l[4]);
if (!Number.isInteger(p) || !Number.isInteger(q) || !Number.isFinite(eqDist) || !Number.isFinite(strength)) {
notify("Cannot read par file, see console for bad line", 'error');
console.log("Error on par line", i);
console.log(l);
return;
}
// if its a torsional ANM then there are additional parameters on some lines
let extraParams = [];
if (l.length > 5) {
Expand All @@ -226,7 +235,6 @@ function readParFile(system, reader) {
if (Number.isInteger(p) && Number.isInteger(q)) {
net.reducedEdges.addEdge(p, q, eqDist, type, strength, extraParams);
}
// if (particle1 == undefined) console.log(i)
}
;
// Create and Fill Vectors
Expand Down
2 changes: 1 addition & 1 deletion dist/file_handling/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class TrajectoryReader {
centerAndPBC(system.getMonomers(), newBox);
if (forceHandler)
forceHandler.redraw();
// Signal that config has been loaded. This is used by the trajectory video loader
// Signal that config has been loaded. This is used by the trajectory video loader.
document.dispatchEvent(new Event('nextConfigLoaded'));
}
}
21 changes: 20 additions & 1 deletion dist/model/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ class Network {
}
}
;
reCalculateRotations() {
for (let t = 0; t < this.reducedEdges.total; t++) {
let i = this.reducedEdges.p1[t];
let j = this.reducedEdges.p2[t];
let newRot = this.elemcoords.rotation(i, j);
this.fillVec('rotations', 4, t, [newRot.w, newRot.z, newRot.y, newRot.x]);
}
this.callUpdates(["instanceRotation"]);
}
;
updatePositions() {
// update all coordinates
this.elemcoords.xI = this.particles.map(e => e.getPos().x);
Expand All @@ -292,11 +302,20 @@ class Network {
let i = this.reducedEdges.p1[t];
let j = this.reducedEdges.p2[t];
let pos = this.center(i, j).toArray();
let dij = this.elemcoords.distance(i, j);
this.fillVec('offsets', 3, t, [pos[0], pos[1], pos[2]]);
this.fillVec('scales', 3, t, [1, dij, 1]);
}
this.callUpdates(["instanceOffset"]);
this.callUpdates(["instanceOffset", "instanceScale"]);
}
;
recalculateVis() {
this.updatePositions();
this.reCalculateRotations();
}
;
// This has never worked for single particles being rotated...
// Apply a rotation to all particles
updateRotations(q) {
for (let t = 0; t < this.reducedEdges.total; t++) {
let currRot = this.getVec('rotations', 4, t);
Expand Down
5 changes: 5 additions & 0 deletions dist/scene/PBC_switchbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ function centerAndPBC(elems, targetBox) {
tmpSystems.forEach(s => s.callUpdates(['instanceOffset']));
if (forceHandler)
forceHandler.redraw();
if (networks.length > 0) {
networks.forEach(n => {
n.recalculateVis();
});
}
render();
}
/**
Expand Down
16 changes: 13 additions & 3 deletions ts/file_handling/aux_readers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function readJson(jsonFile:File, system:System){ // this still doesn't work for
return parseFileWith(jsonFile, parseJson, [system])
}

function readParFile(parFile:File, system:System) {
return parseFileWith(parFile, parsePar, [system])
}

// Creates color overlays
function makeLut(data, key, system) {

Expand Down Expand Up @@ -222,9 +226,9 @@ function readSelectFile(reader) {
}

//reads in an anm parameter file and associates it with the last loaded system.
function readParFile(system, reader) {
let lines = (reader.result as string).split(/[\n]+/g);
function parsePar(lines, system) {

lines = lines.split(/[\n]+/g);
//remove the header
lines = lines.slice(1)

Expand All @@ -242,6 +246,13 @@ function readParFile(system, reader) {
eqDist = parseFloat(l[2]),
type = l[3],
strength = parseFloat(l[4]);

if (!Number.isInteger(p) || !Number.isInteger(q) || !Number.isFinite(eqDist) || !Number.isFinite(strength)) {
notify("Cannot read par file, see console for bad line", 'error')
console.log("Error on par line", i)
console.log(l)
return
}

// if its a torsional ANM then there are additional parameters on some lines
let extraParams = []
Expand All @@ -253,7 +264,6 @@ function readParFile(system, reader) {
if(Number.isInteger(p) && Number.isInteger(q)){
net.reducedEdges.addEdge(p, q, eqDist, type, strength, extraParams);
}
// if (particle1 == undefined) console.log(i)
};
// Create and Fill Vectors
net.initInstances(net.reducedEdges.total);
Expand Down
4 changes: 2 additions & 2 deletions ts/file_handling/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class TrajectoryReader {

// consume a new line from the file
l = lines[i].split(/\s+/);

// get the nucleotide associated with the line
if (system.lines2ele) { currentNucleotide = system.lines2ele.get(i) } // ugly hack to get oxServe to work
else { currentNucleotide = elements.get(i+system.globalStartId); }
Expand All @@ -333,7 +333,7 @@ class TrajectoryReader {
centerAndPBC(system.getMonomers(), newBox);
if (forceHandler) forceHandler.redraw();

// Signal that config has been loaded. This is used by the trajectory video loader
// Signal that config has been loaded. This is used by the trajectory video loader.
document.dispatchEvent(new Event('nextConfigLoaded'));
}
}
21 changes: 20 additions & 1 deletion ts/model/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ class Network {
}
}
;
reCalculateRotations() { // Re-calculate all rotations based on particle positions.
for(let t = 0; t < this.reducedEdges.total; t++){
let i = this.reducedEdges.p1[t];
let j = this.reducedEdges.p2[t];
let newRot = this.elemcoords.rotation(i, j)
this.fillVec('rotations', 4, t, [newRot.w, newRot.z, newRot.y, newRot.x]);
}
this.callUpdates(["instanceRotation"])
}
;
updatePositions(){ // Called by translation.ts
// update all coordinates
this.elemcoords.xI = this.particles.map(e => e.getPos().x);
Expand All @@ -285,11 +295,20 @@ class Network {
let i = this.reducedEdges.p1[t];
let j = this.reducedEdges.p2[t];
let pos = this.center(i, j).toArray();
let dij = this.elemcoords.distance(i, j);
this.fillVec('offsets', 3, t, [pos[0], pos[1], pos[2]]);
this.fillVec('scales', 3, t, [1, dij, 1]);
}
this.callUpdates(["instanceOffset"])
this.callUpdates(["instanceOffset", "instanceScale"]);
}
;
recalculateVis() {
this.updatePositions();
this.reCalculateRotations();
}
;
// This has never worked for single particles being rotated...
// Apply a rotation to all particles
updateRotations(q: THREE.Quaternion){// Called by translation.ts
for(let t = 0; t < this.reducedEdges.total; t++){
let currRot = this.getVec('rotations', 4, t);
Expand Down
5 changes: 5 additions & 0 deletions ts/scene/PBC_switchbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ function centerAndPBC(elems?: BasicElement[], targetBox?: THREE.Vector3) {
affectedSystems.forEach(s=>s.callUpdates(['instanceOffset']));
tmpSystems.forEach(s=>s.callUpdates(['instanceOffset']));
if(forceHandler) forceHandler.redraw();
if (networks.length > 0) {
networks.forEach(n => {
n.recalculateVis();
})
}
render();
}

Expand Down

0 comments on commit 112feb5

Please sign in to comment.