Skip to content

Commit

Permalink
#3651 - different coordinate systems are used in micro and macro mode (
Browse files Browse the repository at this point in the history
…#3726)

Co-authored-by: Konstantin Zharich <[email protected]>
  • Loading branch information
Konstantin1996 and Konstantin Zharich authored Dec 21, 2023
1 parent 9e5ad98 commit d4981dc
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 41 deletions.
10 changes: 5 additions & 5 deletions ketcher-autotests/tests/test-data/KET/five-monomers.ket
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"id": "45",
"position": {
"x": 7.325,
"y": 6.925000000000001
"y": -6.925000000000001
},
"alias": "A",
"templateId": "A___Alanine"
Expand Down Expand Up @@ -184,7 +184,7 @@
"id": "46",
"position": {
"x": 12.4,
"y": 6.775
"y": -6.775
},
"alias": "25R",
"templateId": "25R___2,5-Ribose"
Expand Down Expand Up @@ -425,7 +425,7 @@
"id": "47",
"position": {
"x": 15.8,
"y": 6.675000000000001
"y": -6.675000000000001
},
"alias": "baA",
"templateId": "baA___N-benzyl-adenine"
Expand Down Expand Up @@ -742,7 +742,7 @@
"id": "49",
"position": {
"x": 22.6,
"y": 6.8500000000000005
"y": -6.8500000000000005
},
"alias": "Test-6-Ch",
"templateId": "Test-6-Ch___Test-6-AP-Chem"
Expand Down Expand Up @@ -1148,7 +1148,7 @@
"id": "51",
"position": {
"x": 19.35,
"y": 6.7250000000000005
"y": -6.7250000000000005
},
"alias": "Test-6-Ph",
"templateId": "Test-6-Ph___Test-6-AP-Phosphate"
Expand Down
6 changes: 3 additions & 3 deletions ketcher-autotests/tests/test-data/KET/monomers-and-chem.ket
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"id": "1",
"position": {
"x": 7.9750000000000005,
"y": 5.9
"y": -5.9
},
"alias": "A",
"templateId": "A___Alanine"
Expand Down Expand Up @@ -189,7 +189,7 @@
"id": "3",
"position": {
"x": 13.325000000000001,
"y": 5.825000000000005
"y": -5.825000000000005
},
"alias": "Bal",
"templateId": "Bal___beta-Alanine"
Expand Down Expand Up @@ -324,7 +324,7 @@
"id": "6",
"position": {
"x": 8.075000000000003,
"y": 10.05
"y": -10.05
},
"alias": "Az",
"templateId": "Az___Azide"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"id": "0",
"position": {
"x": 9.850000000000001,
"y": 11.279999995231629
"y": -11.279999995231629,
"z": 0
},
"alias": "baA",
"templateId": "baA___N-benzyl-adenine"
Expand Down Expand Up @@ -368,7 +369,8 @@
"id": "1",
"position": {
"x": 9.850000000000001,
"y": 8.729999995231628
"y": -8.729999995231628,
"z": 0
},
"alias": "12ddR",
"templateId": "12ddR___1',2'-Di-Deoxy-Ribose"
Expand Down Expand Up @@ -563,7 +565,8 @@
"id": "2",
"position": {
"x": 12.4,
"y": 8.729999995231628
"y": -8.729999995231628,
"z": 0
},
"alias": "P",
"templateId": "P___Phosphate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"id": "373",
"position": {
"x": 9.850000000000001,
"y": 11.279999995231629
"y": -11.279999995231629
},
"alias": "baA",
"templateId": "baA___N-benzyl-adenine"
Expand Down Expand Up @@ -366,7 +366,7 @@
"id": "374",
"position": {
"x": 9.850000000000001,
"y": 8.729999995231628
"y": -8.729999995231628
},
"alias": "12ddR",
"templateId": "12ddR___1',2'-Di-Deoxy-Ribose"
Expand Down Expand Up @@ -557,7 +557,7 @@
"id": "376",
"position": {
"x": 12.4,
"y": 8.729999995231628
"y": -8.729999995231628
},
"alias": "P",
"templateId": "P___Phosphate"
Expand Down
20 changes: 10 additions & 10 deletions ketcher-autotests/tests/test-data/KET/monomers-with-bonds.ket
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
"id": "3",
"position": {
"x": 8.200000000000001,
"y": 2.475
"y": -2.475
},
"alias": "Test-6-P",
"templateId": "Test-6-P___Test-6-AP-Peptide"
Expand Down Expand Up @@ -731,7 +731,7 @@
"id": "4",
"position": {
"x": 10.9,
"y": 2.375
"y": -2.375
},
"alias": "Test-6-P",
"templateId": "Test-6-P___Test-6-AP-Peptide"
Expand All @@ -741,7 +741,7 @@
"id": "5",
"position": {
"x": 13.725000000000001,
"y": 2.275
"y": -2.275
},
"alias": "Test-6-P",
"templateId": "Test-6-P___Test-6-AP-Peptide"
Expand All @@ -751,7 +751,7 @@
"id": "6",
"position": {
"x": 7.8500000000000005,
"y": 7.300000000000001
"y": -7.300000000000001
},
"alias": "Test-6-P",
"templateId": "Test-6-P___Test-6-AP-Peptide"
Expand All @@ -761,7 +761,7 @@
"id": "7",
"position": {
"x": 10.65,
"y": 7.1000000000000005
"y": -7.1000000000000005
},
"alias": "Test-6-P",
"templateId": "Test-6-P___Test-6-AP-Peptide"
Expand All @@ -771,7 +771,7 @@
"id": "8",
"position": {
"x": 13.725000000000001,
"y": 7.1000000000000005
"y": -7.1000000000000005
},
"alias": "Test-6-P",
"templateId": "Test-6-P___Test-6-AP-Peptide"
Expand All @@ -781,7 +781,7 @@
"id": "9",
"position": {
"x": 10.825000000000001,
"y": 4.7250000000000005
"y": -4.7250000000000005
},
"alias": "Test-6-P",
"templateId": "Test-6-P___Test-6-AP-Peptide"
Expand All @@ -791,7 +791,7 @@
"id": "19",
"position": {
"x": 2.2,
"y": 8.9
"y": -8.9
},
"alias": "A",
"templateId": "A___Adenine"
Expand Down Expand Up @@ -996,7 +996,7 @@
"id": "20",
"position": {
"x": 2.2,
"y": 6.3500000000000005
"y": -6.3500000000000005
},
"alias": "R",
"templateId": "R___Ribose"
Expand Down Expand Up @@ -1237,7 +1237,7 @@
"id": "22",
"position": {
"x": 4.75,
"y": 6.3500000000000005
"y": -6.3500000000000005
},
"alias": "P",
"templateId": "P___Phosphate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"id": "76",
"position": {
"x": 10.325000000000001,
"y": 5.2250000000000005
"y": -5.2250000000000005
},
"alias": "A",
"templateId": "A___Alanine"
Expand Down Expand Up @@ -195,7 +195,7 @@
"id": "77",
"position": {
"x": 14.525,
"y": 5.125
"y": -5.125
},
"alias": "Edc",
"templateId": "Edc___S-ethylthiocysteine"
Expand Down Expand Up @@ -398,7 +398,7 @@
"id": "78",
"position": {
"x": 19.175,
"y": 5.300000000000001
"y": -5.300000000000001
},
"alias": "A6OH",
"templateId": "A6OH___6-amino-hexanol"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"id": "36",
"position": {
"x": 12.625,
"y": 9.575000000000001
"y": -9.575000000000001
},
"alias": "Bal",
"templateId": "Bal___beta-Alanine"
Expand Down Expand Up @@ -170,7 +170,7 @@
"id": "37",
"position": {
"x": 17.025000000000002,
"y": 9.675
"y": -9.675
},
"alias": "Edc",
"templateId": "Edc___S-ethylthiocysteine"
Expand Down Expand Up @@ -373,7 +373,7 @@
"id": "38",
"position": {
"x": 20.775000000000002,
"y": 9.725000000000001
"y": -9.725000000000001
},
"alias": "Test-6-Ch",
"templateId": "Test-6-Ch___Test-6-AP-Chem"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

-INDIGO-12152318292D
-INDIGO-12202313442D

0 0 0 0 0 0 0 0 0 0 0 V3000
M V30 BEGIN CTAB
M V30 COUNTS 3 2 0 0 0
M V30 BEGIN ATOM
M V30 1 A 7.975 5.9 0.0 0 CLASS=AA ATTCHORD=(4 2 Br 3 Al)
M V30 2 Bal 13.325 5.825 0.0 0 CLASS=AA ATTCHORD=(2 1 Al)
M V30 3 Az 8.075 10.05 0.0 0 CLASS=CHEM ATTCHORD=(2 1 Al)
M V30 1 A 7.975 -5.9 0.0 0 CLASS=AA ATTCHORD=(4 2 Br 3 Al)
M V30 2 Bal 13.325 -5.825 0.0 0 CLASS=AA ATTCHORD=(2 1 Al)
M V30 3 Az 8.075 -10.05 0.0 0 CLASS=CHEM ATTCHORD=(2 1 Al)
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 1 1 2
Expand Down
7 changes: 7 additions & 0 deletions packages/ketcher-core/src/domain/entities/Axis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum Axis {
x = 'x',
y = 'y',
z = 'z',
}

export type Axises = 'x' | 'y' | 'z';
1 change: 1 addition & 0 deletions packages/ketcher-core/src/domain/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ export * from './Chem';
export * from './Sugar';
export * from './RNABase';
export * from './Phosphate';
export * from './Axis';
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import {
} from 'application/formatters/types/ket';
import { Struct, Vec2 } from 'domain/entities';
import { DrawingEntitiesManager } from 'domain/entities/DrawingEntitiesManager';
import { switchIntoChemistryCoordSystem } from 'domain/serializers/ket/helpers';

export function monomerToDrawingEntity(
node: IKetMonomerNode,
template: IKetMonomerTemplate,
struct: Struct,
drawingEntitiesManager: DrawingEntitiesManager,
) {
const position: Vec2 = switchIntoChemistryCoordSystem(
new Vec2(node.position.x, node.position.y),
);
return drawingEntitiesManager.addMonomer(
{
struct,
Expand All @@ -30,6 +34,6 @@ export function monomerToDrawingEntity(
attachmentPoints: template.attachmentPoints,
seqId: node.seqid,
},
new Vec2(node.position.x, node.position.y),
position,
);
}
17 changes: 17 additions & 0 deletions packages/ketcher-core/src/domain/serializers/ket/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
***************************************************************************/

import { Vec2, Axis, Axises } from 'domain/entities';
import { cloneDeepWith, cloneDeep } from 'lodash';

const customizer = (value: any) => {
Expand All @@ -34,3 +35,19 @@ export const setMonomerPrefix = (monomerId: number) => `monomer${monomerId}`;
export const getKetRef = (entityId: string) => {
return { $ref: entityId };
};

const rotateCoordAxisBy180Degrees = (position: Vec2, axis: Axises): Vec2 => {
const rotatedPosition = {
x: position.x,
y: position.y,
z: position.z,
};

rotatedPosition[axis] = -rotatedPosition[axis];

return new Vec2(rotatedPosition.x, rotatedPosition.y, rotatedPosition.z);
};

export const switchIntoChemistryCoordSystem = (position: Vec2) => {
return rotateCoordAxisBy180Degrees(position, Axis.y);
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
getKetRef,
setMonomerPrefix,
setMonomerTemplatePrefix,
switchIntoChemistryCoordSystem,
} from 'domain/serializers/ket/helpers';
import { BaseMonomer } from 'domain/entities/BaseMonomer';
import { validate } from 'domain/serializers/ket/validate';
Expand Down Expand Up @@ -439,10 +440,9 @@ export class KetSerializer implements Serializer<Struct> {
fileContent[monomerName] = {
type: 'monomer',
id: monomer.id.toString(),
position: {
x: monomer.position.x,
y: monomer.position.y,
},
position: switchIntoChemistryCoordSystem(
new Vec2(monomer.position.x, monomer.position.y),
),
alias: monomer.label,
templateId,
seqid: monomer.monomerItem.seqId,
Expand Down
Loading

0 comments on commit d4981dc

Please sign in to comment.