Skip to content

#9741 - TODO | Feature: Improve atom placement layout algorithm#9815

Open
St-Permiakov wants to merge 5 commits into
masterfrom
9741-todo-feature-improve-atom-placement-layout-algorithm
Open

#9741 - TODO | Feature: Improve atom placement layout algorithm#9815
St-Permiakov wants to merge 5 commits into
masterfrom
9741-todo-feature-improve-atom-placement-layout-algorithm

Conversation

@St-Permiakov
Copy link
Copy Markdown
Collaborator

@St-Permiakov St-Permiakov commented Apr 20, 2026

How the feature works? / How did you fix the issue?

Improve New Atom Placement to Avoid Overlaps

Enhanced the atomForNewBond algorithm to consider both angular gaps and true spatial collisions.

  • New atoms are now placed to minimize overlap with nearby atoms and bonds, not just neighbor directions.
  • Added spatial scoring: candidate positions too close to existing atoms or bonds are penalized.
  • Preserved special cases (zig-zag, 180° for double/triple bonds).
  • No changes to public API; only internal placement logic improved.

This results in cleaner, less-overlapping structures when adding new atoms to crowded or branched molecules.

Added focused unit coverage for atomForNewBond placement logic. The tests build minimal molecular structures and assert that the generated new-atom position avoids nearby visible atoms and bond segments, chooses the widest available sector for branched atoms, and preserves existing special-case behavior for 180 degree multiple-bond extension and zig-zag chain growth.

This helps catch regressions in the new collision-avoidance scoring without relying on full editor interaction tests.

Check list

  • unit-tests written
  • e2e-tests written
  • documentation updated
  • PR name follows the pattern #1234 – issue name
  • branch name doesn't contain '#'
  • PR is linked with the issue
  • base branch (master or release/xx) is correct
  • task status changed to "Code review"
  • reviewers are notified about the pull request

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves Ketcher’s internal atomForNewBond placement logic to reduce overlaps in crowded structures by adding an angle-optimization step that scores candidate directions using both angular “blocked sectors” and spatial collision penalties against nearby atoms/bonds.

Changes:

  • Added angle utilities and a new optimization routine to pick a direction near the preferred angular gap while penalizing collisions.
  • Extended environment analysis for placement by collecting “blocked” directions, nearby atoms, and nearby bond segments.
  • Kept existing special-case behavior (zig-zag for a single neighbor, and 180° placement for certain bond-type sequences).

Comment thread packages/ketcher-core/src/application/editor/actions/utils.ts Outdated
Comment thread packages/ketcher-core/src/application/editor/actions/utils.ts Outdated
Comment thread packages/ketcher-core/src/application/editor/actions/utils.ts Outdated
Comment thread packages/ketcher-core/src/application/editor/actions/utils.ts Outdated
@St-Permiakov St-Permiakov force-pushed the 9741-todo-feature-improve-atom-placement-layout-algorithm branch from 2aa2ae4 to b3f3d9a Compare May 13, 2026 11:52
@AlexeyGirin
Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 3, 2026

@copilot resolve the merge conflicts in this pull request

Conflicts are resolved by merging origin/master into this branch and fixing the conflict in packages/ketcher-core/__tests__/application/editor/actions/bond.test.ts.

Included in commit df7d70fb9.

Copilot AI requested a review from AlexeyGirin June 3, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TODO | Feature: Improve atom placement layout algorithm

4 participants