Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4530 - Add ability to define attachment points for molecules fixes #4727

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ export class MacromoleculesConverter {
const atomIdMap = monomerToAtomIdMap.get(monomer);

return {
attachmentAtomId:
globalAttachmentAtomId:
isNumber(attachmentPoint?.attachmentAtom) &&
atomIdMap?.get(attachmentPoint?.attachmentAtom as number),
attachmentAtomId:
isNumber(attachmentPoint?.attachmentAtom) &&
attachmentPoint?.attachmentAtom,
attachmentPointNumber,
};
}
Expand Down Expand Up @@ -178,15 +181,15 @@ export class MacromoleculesConverter {
drawingEntitiesManager.polymerBonds.forEach((polymerBond) => {
assert(polymerBond.secondMonomer);
const {
attachmentAtomId: beginAtom,
globalAttachmentAtomId: beginAtom,
attachmentPointNumber: beginSuperatomAttachmentPointNumber,
} = this.findAttachmentPointAtom(
polymerBond,
polymerBond.firstMonomer,
monomerToAtomIdMap,
);
const {
attachmentAtomId: endAtom,
globalAttachmentAtomId: endAtom,
attachmentPointNumber: endSuperatomAttachmentPointNumber,
} = this.findAttachmentPointAtom(
polymerBond,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export class KetSerializer implements Serializer<Struct> {
monomerToAtomIdMap: Map<BaseMonomer, Map<number, number>>,
struct: Struct,
): IKetConnectionMoleculeEndPoint {
const { attachmentAtomId } =
const { attachmentAtomId, globalAttachmentAtomId } =
MacromoleculesConverter.findAttachmentPointAtom(
polymerBond,
monomer,
Expand All @@ -503,7 +503,7 @@ export class KetSerializer implements Serializer<Struct> {

return {
moleculeId: `mol${
struct.atoms.get(attachmentAtomId as number)?.fragment
struct.atoms.get(globalAttachmentAtomId as number)?.fragment
}`,
atomId: `${attachmentAtomId as number}`,
};
Expand Down
14 changes: 13 additions & 1 deletion packages/ketcher-react/src/script/ui/state/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { supportedSGroupTypes } from './constants';
import { setAnalyzingFile } from './request';
import tools from '../action/tools';
import { isNumber } from 'lodash';

export function onAction(action) {
if (action && action.dialog) {
Expand Down Expand Up @@ -149,6 +150,14 @@ export function load(struct: Struct, options?) {
const hasUnsupportedGroups = parsedStruct.sgroups.some(
(sGroup) => !supportedSGroupTypes[sGroup.type],
);
const hasMoleculeToMonomerConnections = parsedStruct.bonds.find(
Copy link
Collaborator

@svvald svvald Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's minor, but it seems that .some might fit better semantically here rather than .find as you return some flag of whether any bond meets your condition, not the bond itself

(_, bond) => {
return (
isNumber(bond.beginSuperatomAttachmentPointNumber) ||
isNumber(bond.endSuperatomAttachmentPointNumber)
);
},
);

if (hasUnsupportedGroups) {
await editor.event.confirm.dispatch();
Expand All @@ -157,7 +166,10 @@ export function load(struct: Struct, options?) {
);
}

parsedStruct.rescale(); // TODO: move out parsing?
// scaling works bad with molecule-to-monomer connections
if (!hasMoleculeToMonomerConnections) {
parsedStruct.rescale(); // TODO: move out parsing?
}

if (editor.struct().atoms.size) {
// NB: reset id
Expand Down
Loading