-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/epam/ketcher into 2078-ce…
…nter-molecules-after-layout-and-pasting
- Loading branch information
Showing
11 changed files
with
329 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+13 KB
....ts-snapshots/Open-V3000-file-with-G-Groups-with-Fragments-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions
60
ketcher-autotests/tests/test-data/RGroup-With-Fragments.mol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
Marvin 02211216212D | ||
|
||
0 0 0 0 0 999 V3000 | ||
M V30 BEGIN CTAB | ||
M V30 COUNTS 8 7 0 0 0 | ||
M V30 BEGIN ATOM | ||
M V30 1 C 7.6835 -7.3342 0 0 | ||
M V30 2 C 9.0171 -6.5642 0 0 | ||
M V30 3 C 10.3508 -7.3342 0 0 | ||
M V30 4 C 11.6845 -6.5642 0 0 | ||
M V30 5 C 13.0181 -7.3342 0 0 | ||
M V30 6 C 14.3518 -6.5642 0 0 | ||
M V30 7 C 15.6855 -7.3342 0 0 | ||
M V30 8 R# 17.0191 -6.5642 0 0 RGROUPS=(1 1) | ||
M V30 END ATOM | ||
M V30 BEGIN BOND | ||
M V30 1 1 1 2 | ||
M V30 2 1 2 3 | ||
M V30 3 1 3 4 | ||
M V30 4 1 4 5 | ||
M V30 5 1 5 6 | ||
M V30 6 1 6 7 | ||
M V30 7 1 7 8 | ||
M V30 END BOND | ||
M V30 END CTAB | ||
M V30 BEGIN RGROUP 1 | ||
M V30 RLOGIC 0 0 >0 | ||
M V30 BEGIN CTAB | ||
M V30 COUNTS 3 2 0 0 0 | ||
M V30 BEGIN ATOM | ||
M V30 1 C 9.0283 -18.013 0 0 ATTCHPT=1 | ||
M V30 2 Br 10.362 -18.7831 0 0 | ||
M V30 3 O 9.0283 -16.473 0 0 | ||
M V30 END ATOM | ||
M V30 BEGIN BOND | ||
M V30 1 1 1 2 | ||
M V30 2 2 1 3 | ||
M V30 END BOND | ||
M V30 END CTAB | ||
M V30 BEGIN CTAB | ||
M V30 COUNTS 6 5 0 0 0 | ||
M V30 BEGIN ATOM | ||
M V30 1 C 13.7114 -17.3173 0 0 ATTCHPT=1 | ||
M V30 2 C 15.0451 -18.0874 0 0 | ||
M V30 3 F 16.1608 -16.9865 0 0 | ||
M V30 4 F 14.6601 -19.6326 0 0 | ||
M V30 5 F 16.3029 -18.8293 0 0 | ||
M V30 6 O 13.7114 -15.7773 0 0 | ||
M V30 END ATOM | ||
M V30 BEGIN BOND | ||
M V30 1 1 1 2 | ||
M V30 2 1 2 3 | ||
M V30 3 1 2 4 | ||
M V30 4 1 2 5 | ||
M V30 5 2 1 6 | ||
M V30 END BOND | ||
M V30 END CTAB | ||
M V30 END RGROUP | ||
M END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...ts__/domain/serializers/ket/fromKet/mergeFragmentsToStruct/mergeFragmentsToStruct.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import { Struct } from 'domain/entities'; | ||
import { KetItem } from 'domain/serializers/ket/fromKet/types'; | ||
import { | ||
atomToStruct, | ||
bondToStruct, | ||
} from 'domain/serializers/ket/fromKet/moleculeToStruct'; | ||
import { mergeFragmentsToStruct } from 'domain/serializers/ket/fromKet/mergeFragmentsToStruct'; | ||
|
||
describe('mergeFragmentsToStruct', () => { | ||
it('should return the same struct when ketItem is empty', () => { | ||
const emptyKetItem: KetItem = {}; | ||
const struct: Struct = new Struct(); | ||
const result = mergeFragmentsToStruct(emptyKetItem, struct); | ||
|
||
expect(result.atoms).toEqual(struct.atoms); | ||
expect(result.bonds).toEqual(struct.bonds); | ||
}); | ||
|
||
it('should merge single fragment into struct', () => { | ||
const singleFragmentKetItem: KetItem = { | ||
fragments: [ | ||
{ | ||
atoms: [ | ||
{ | ||
attachmentPoints: 1, | ||
label: 'C', | ||
location: [1, 2, 3], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const struct: Struct = new Struct(); | ||
const expectedStruct = new Struct(); | ||
expectedStruct.atoms.add( | ||
atomToStruct({ | ||
attachmentPoints: 1, | ||
label: 'C', | ||
location: [1, 2, 3], | ||
}), | ||
); | ||
|
||
const result = mergeFragmentsToStruct(singleFragmentKetItem, struct); | ||
expect(result.atoms).toEqual(expectedStruct.atoms); | ||
expect(result.bonds).toEqual(expectedStruct.bonds); | ||
}); | ||
|
||
it('should merge multiple fragments with no bonds into struct', () => { | ||
const multiFragmentKetItem: KetItem = { | ||
fragments: [ | ||
{ | ||
atoms: [ | ||
{ | ||
attachmentPoints: 1, | ||
label: 'C', | ||
location: [1, 2, 3], | ||
}, | ||
], | ||
}, | ||
{ | ||
atoms: [ | ||
{ | ||
attachmentPoints: 1, | ||
label: 'O', | ||
location: [4, 5, 6], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const struct = new Struct(); | ||
const expectedStruct = new Struct(); | ||
expectedStruct.atoms.add( | ||
atomToStruct({ | ||
attachmentPoints: 1, | ||
label: 'C', | ||
location: [1, 2, 3], | ||
}), | ||
); | ||
expectedStruct.atoms.add( | ||
atomToStruct({ | ||
attachmentPoints: 1, | ||
label: 'O', | ||
location: [4, 5, 6], | ||
}), | ||
); | ||
|
||
const result = mergeFragmentsToStruct(multiFragmentKetItem, struct); | ||
expect(result.atoms).toEqual(expectedStruct.atoms); | ||
expect(result.bonds).toEqual(expectedStruct.bonds); | ||
}); | ||
|
||
it('should merge multiple fragments with bonds into struct', () => { | ||
const multiFragmentKetItem: KetItem = { | ||
fragments: [ | ||
{ | ||
atoms: [ | ||
{ | ||
attachmentPoints: 1, | ||
label: 'C', | ||
location: [1, 2, 3], | ||
}, | ||
{ | ||
attachmentPoints: 1, | ||
label: 'O', | ||
location: [4, 5, 6], | ||
}, | ||
], | ||
bonds: [ | ||
{ | ||
type: 1, | ||
atoms: [0, 1], | ||
}, | ||
], | ||
}, | ||
{ | ||
atoms: [ | ||
{ | ||
attachmentPoints: 1, | ||
label: 'N', | ||
location: [7, 8, 9], | ||
}, | ||
], | ||
bonds: [], | ||
}, | ||
], | ||
}; | ||
|
||
const struct: Struct = new Struct(); | ||
const expectedStruct = new Struct(); | ||
const expectedAtoms = [ | ||
{ | ||
attachmentPoints: 1, | ||
label: 'C', | ||
location: [1, 2, 3], | ||
}, | ||
{ | ||
attachmentPoints: 1, | ||
label: 'O', | ||
location: [4, 5, 6], | ||
}, | ||
{ | ||
attachmentPoints: 1, | ||
label: 'N', | ||
location: [7, 8, 9], | ||
}, | ||
]; | ||
expectedAtoms.forEach((atom) => { | ||
expectedStruct.atoms.add(atomToStruct(atom)); | ||
}); | ||
expectedStruct.bonds.add( | ||
bondToStruct({ | ||
type: 1, | ||
atoms: [0, 1], | ||
}), | ||
); | ||
|
||
const result = mergeFragmentsToStruct(multiFragmentKetItem, struct); | ||
expect(result.atoms).toEqual(expectedStruct.atoms); | ||
expect(result.bonds).toEqual(expectedStruct.bonds); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/ketcher-core/src/domain/serializers/ket/fromKet/mergeFragmentsToStruct.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Struct } from 'domain/entities'; | ||
import { atomToStruct, bondToStruct } from './moleculeToStruct'; | ||
import { KetItem } from './types'; | ||
|
||
export function mergeFragmentsToStruct( | ||
ketItem: KetItem, | ||
struct: Struct, | ||
): Struct { | ||
let atomsOffset = 0; | ||
if (ketItem.fragments) { | ||
ketItem.fragments.forEach((fragment) => { | ||
fragment.atoms?.forEach((atom) => struct.atoms.add(atomToStruct(atom))); | ||
fragment.bonds?.forEach((bond) => | ||
struct.bonds.add(bondToStruct(bond, atomsOffset)), | ||
); | ||
atomsOffset += fragment.atoms?.length || 0; | ||
}); | ||
} | ||
return struct; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/ketcher-core/src/domain/serializers/ket/fromKet/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export interface KetAtom { | ||
attachmentPoints: number; | ||
label: string; | ||
location: [number, number, number]; | ||
} | ||
|
||
export interface KetBond { | ||
type: number; | ||
atoms: [number, number]; | ||
} | ||
|
||
export interface KetFragment { | ||
atoms?: KetAtom[]; | ||
bonds?: KetBond[]; | ||
} | ||
|
||
export interface KetItem { | ||
fragments?: KetFragment[]; | ||
rlogic?: { | ||
number: number; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.