Skip to content
Snippets Groups Projects
Commit 30faff7a authored by Lukas Pravda's avatar Lukas Pravda
Browse files

fix broken reinitialize from ligend view when bm was active

parent 1aa7bf07
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,8 @@ class Visualization {
// #region data properties
private environment: Model.Environment;
private pdbId: string;
private bindingSite: Model.BindingSite;
private bindingSites: Model.BindingSite[];
private presentBindingSite: Model.BindingSite;
private depiction: Depiction;
private visualsMapper: VisualsMapper;
......@@ -41,6 +42,7 @@ class Visualization {
this.visualsMapper = new VisualsMapper(this.environment);
this.rProvider = ResidueProvider.getInstance(this.environment);
this.fullScreen = false;
this.bindingSites = new Array<Model.BindingSite>();
if (uiParameters === undefined) uiParameters = new Config.UIParameters();
......@@ -295,11 +297,13 @@ class Visualization {
if (this.depiction === undefined || this.depiction.ccdId !== body.ligand.chem_comp_id) {
this.initLigandDisplay(body.ligand.chem_comp_id).then(() => {
this.bindingSite = new Model.BindingSite().fromLigand(key, body, this.depiction);
this.presentBindingSite = new Model.BindingSite().fromLigand(key, body, this.depiction);
this.bindingSites.push(this.presentBindingSite);
this.setupLigandScene();
});
} else {
this.bindingSite = new Model.BindingSite().fromLigand(key, body, this.depiction);
this.presentBindingSite = new Model.BindingSite().fromLigand(key, body, this.depiction);
this.bindingSites.push(this.presentBindingSite);
this.setupLigandScene();
}
}
......@@ -316,10 +320,11 @@ class Visualization {
public addBoundMoleculeInteractions(data: any, bmId: string) {
let key = Object.keys(data)[0];
this.interactionsData = data;
this.presentBindingSite = new Model.BindingSite().fromBoundMolecule(key, data[key][0]);
this.bindingSite = new Model.BindingSite().fromBoundMolecule(key, data[key][0]);
this.bindingSite.bmId = bmId;
let ligands = this.bindingSite.residues.filter(x => x.isLigand);
this.bindingSites.push(this.presentBindingSite);
this.presentBindingSite.bmId = bmId;
let ligands = this.presentBindingSite.residues.filter(x => x.isLigand);
if (ligands.length === 1) this.initLigandInteractions(this.pdbId, ligands[0].authorResidueNumber, ligands[0].chainId);
else this.setupScene();
......@@ -362,7 +367,7 @@ class Visualization {
let dataBlob = new Blob([JSON.stringify(this.interactionsData, null, 4)], { type: 'application/json' });
downloadLink.href = URL.createObjectURL(dataBlob);
downloadLink.download = this.interactionsData === undefined ? 'no name.json' : `${this.pdbId}_${this.bindingSite.bmId}_interactions.json`;
downloadLink.download = this.interactionsData === undefined ? 'no name.json' : `${this.pdbId}_${this.presentBindingSite.bmId}_interactions.json`;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
......@@ -376,8 +381,21 @@ class Visualization {
*/
public reinitialize() {
if (this.depiction === undefined) this.setupScene();
else this.setupLigandScene();
if (this.bindingSites.length > 1 && this.depiction !== undefined) {
this.presentBindingSite = this.bindingSites[0];
this.bindingSites.pop();
this.depictionRoot.selectAll('*').remove();
this.depiction = undefined;
this.setupScene().then(() => this.centerScene());
}
else if (this.depiction === undefined) {
this.setupScene().then(() => this.centerScene());
}
else {
this.setupLigandScene().then(() => this.centerScene());
}
this.hideLigandLabel();
}
......@@ -462,7 +480,7 @@ class Visualization {
}
private getSVGName(): string {
if (this.bindingSite !== undefined) return `${this.bindingSite.bmId}.svg`;
if (this.presentBindingSite !== undefined) return `${this.presentBindingSite.bmId}.svg`;
if (this.depiction !== undefined) return `${this.depiction.ccdId}.svg`;
return 'blank.svg';
......@@ -562,7 +580,7 @@ class Visualization {
private setupLinks() {
this.links = this.linksRoot
.selectAll()
.data(this.bindingSite.links)
.data(this.presentBindingSite.links)
.enter().append('g');
this.links
......@@ -657,10 +675,10 @@ class Visualization {
this.wipeOutVisuals();
this.setupLinks();
this.bindingSite.interactionNodes
this.presentBindingSite.interactionNodes
.filter((x: Model.InteractionNode) => !x.residue.isLigand)
.forEach((x: Model.InteractionNode) => {
let lnks = this.bindingSite.links
let lnks = this.presentBindingSite.links
.filter((y: Model.LigandResidueLink) => y.containsInteractionNode(x))
.map((y: Model.LigandResidueLink) => [].concat.apply([], y.interaction.map(z => z.sourceAtoms)));
......@@ -673,13 +691,13 @@ class Visualization {
// setup nodes; wait for resources to be ready
this.bindingSite.interactionNodes.forEach(x => this.rProvider.downloadAnnotation(x.residue));
this.presentBindingSite.interactionNodes.forEach(x => this.rProvider.downloadAnnotation(x.residue));
await Promise.all(this.rProvider.downloadPromises);
await Promise.all([this.visualsMapper.graphicsPromise, this.visualsMapper.mappingPromise]);
this.nodes = this.nodesRoot.append('g')
.selectAll()
.data(this.bindingSite.interactionNodes)
.data(this.presentBindingSite.interactionNodes)
.enter().append('g');
......@@ -708,7 +726,7 @@ class Visualization {
let charge = d3.forceManyBody().strength(-100).distanceMin(40).distanceMax(80);
let collision = d3.forceCollide().radius(45);
this.simulation = d3.forceSimulation(this.bindingSite.interactionNodes)
this.simulation = d3.forceSimulation(this.presentBindingSite.interactionNodes)
.force('link', forceLink)
.force('charge', charge) //strength
.force('collision', collision)
......@@ -732,13 +750,13 @@ class Visualization {
this.setupLinks();
// setup nodes; wait for resources to be ready
this.bindingSite.interactionNodes.forEach(x => ResidueProvider.getInstance(this.environment).downloadAnnotation(x.residue));
this.presentBindingSite.interactionNodes.forEach(x => ResidueProvider.getInstance(this.environment).downloadAnnotation(x.residue));
await Promise.all(this.rProvider.downloadPromises);
await Promise.all([this.visualsMapper.graphicsPromise, this.visualsMapper.mappingPromise]);
this.nodes = this.nodesRoot
.selectAll()
.data(this.bindingSite.interactionNodes)
.data(this.presentBindingSite.interactionNodes)
.enter().append('g')
.attr('class', (e: Model.InteractionNode) => `pdb-lig-env-svg-node pdb-lig-env-svg-${e.residue.getResidueType()}-res`)
.on('click', (x: Model.InteractionNode, i: number, g: any) => this.selectLigand(x, i, g))
......@@ -757,7 +775,7 @@ class Visualization {
this.addNodeLabels(this.nodes);
let forceLink = d3.forceLink()
.links(this.bindingSite.links)
.links(this.presentBindingSite.links)
.distance((x: Model.Link) => (<Model.InteractionNode>x.source).residue.isLigand && (<Model.InteractionNode>x.target).residue.isLigand ? 55 : 150)
.strength(0.5);
......@@ -765,7 +783,7 @@ class Visualization {
let collision = d3.forceCollide(45);
let center = d3.forceCenter(this.parent.offsetWidth / 2, this.parent.offsetHeight / 2);
this.simulation = d3.forceSimulation(this.bindingSite.interactionNodes)
this.simulation = d3.forceSimulation(this.presentBindingSite.interactionNodes)
.force('link', forceLink)
.force('charge', charge) //strength
.force('collision', collision)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment