Skip to content
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
16 changes: 15 additions & 1 deletion src/layout/engine/cleanup/stage-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ function resolveParentStageResult(stageResults, baselineStage, parentStage, best
return null;
}

function movesFixedAtoms(layoutGraph, parentCoords, candidateCoords) {
if (!layoutGraph || layoutGraph.options?.preserveFixed === false || !(layoutGraph.fixedCoords?.size > 0)) {
return false;
}
for (const atomId of layoutGraph.fixedCoords.keys()) {
const before = parentCoords.get(atomId);
const after = candidateCoords.get(atomId);
if (before && after && (before.x !== after.x || before.y !== after.y)) {
return true;
}
}
return false;
}

/**
* Executes a cleanup-stage DAG while tracking the current incumbent and stage sidecars.
* @param {object[]} stages - Ordered stage descriptors.
Expand Down Expand Up @@ -209,7 +223,7 @@ export function runStageGraph(stages, baselineStage, context, seedState = null)
}

const prevBestStage = bestStage;
const accepted = !stage.comparatorFn || stage.comparatorFn(stageResult, bestStage, context, stageResults);
const accepted = !movesFixedAtoms(context.layoutGraph, parentStageResult.coords, stageResult.coords) && (!stage.comparatorFn || stage.comparatorFn(stageResult, bestStage, context, stageResults));
stageExecution.accepted = accepted;
if (accepted) {
bestStage = stageResult;
Expand Down
10 changes: 10 additions & 0 deletions src/layout/engine/cleanup/symmetry-tidy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { angleOf, angularDifference, centroidForAtomIds, rotate, sub } from '../
const IDEMPOTENT_AXIS_EPSILON = 1e-12;
const LOCAL_AXIS_SNAP_ANGLE_EPSILON = Math.PI / 720;

function isFixedAtom(layoutGraph, atomId) {
return layoutGraph?.options?.preserveFixed !== false && layoutGraph?.fixedCoords?.has(atomId) === true;
}

/**
* Returns the qualifying fused ring-junction pairs that should be snapped to an axis.
* @param {object} layoutGraph - Layout graph shell.
Expand Down Expand Up @@ -43,6 +47,9 @@ function collectJunctionTargets(layoutGraph) {
if (!component) {
continue;
}
if (component.atomIds.some(atomId => isFixedAtom(layoutGraph, atomId))) {
continue;
}
if (!targets.has(component.id)) {
targets.set(component.id, {
atomIds: [...component.atomIds],
Expand Down Expand Up @@ -330,6 +337,9 @@ export function tidySymmetry(inputCoords, options = {}) {

for (const [atomId, position] of junctionSnap.coords) {
const nextPosition = { ...position };
if (isFixedAtom(options.layoutGraph, atomId)) {
continue;
}
if (Math.abs(nextPosition.x) <= epsilon) {
const snappedPosition = { ...nextPosition, x: 0 };
if (!wouldAxisSnapDistortLocalGeometry(options.layoutGraph, coords, atomId, snappedPosition)) {
Expand Down
6 changes: 5 additions & 1 deletion src/layout/engine/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -16600,6 +16600,7 @@ export function runPipeline(molecule, options = {}) {
const postRoutingLargeDirtyResidualRetouch = timeFinalRetouch('postRoutingLargeDirtyResidualRetouch', () =>
runLargeMoleculeResidualRetouch(layoutGraph, finalCoords, {
bondLength: normalizedOptions.bondLength,
frozenAtomIds: placement.frozenAtomIds,
residualOnly: true
})
);
Expand Down Expand Up @@ -16827,7 +16828,8 @@ export function runPipeline(molecule, options = {}) {
if (placement.placedFamilies.includes('large-molecule') || familySummary.primaryFamily === 'large-molecule') {
const largeMoleculeResidualRetouch = timeFinalRetouch('largeMoleculeResidualRetouch', () =>
runLargeMoleculeResidualRetouch(layoutGraph, finalCoords, {
bondLength: normalizedOptions.bondLength
bondLength: normalizedOptions.bondLength,
frozenAtomIds: placement.frozenAtomIds
})
);
if (largeMoleculeResidualRetouch.changed) {
Expand Down Expand Up @@ -18623,6 +18625,7 @@ export function runPipeline(molecule, options = {}) {
const lateLargeMoleculeResidualRetouch = timeFinalRetouch('lateLargeMoleculeResidualRetouch', () =>
runLargeMoleculeResidualRetouch(layoutGraph, finalCoords, {
bondLength: normalizedOptions.bondLength,
frozenAtomIds: placement.frozenAtomIds,
residualOnly: true
})
);
Expand Down Expand Up @@ -18711,6 +18714,7 @@ export function runPipeline(molecule, options = {}) {
const finalLargeMoleculeResidualRetouch = timeFinalRetouch('finalLargeMoleculeResidualRetouch', () =>
runLargeMoleculeResidualRetouch(layoutGraph, finalCoords, {
bondLength: normalizedOptions.bondLength,
frozenAtomIds: placement.frozenAtomIds,
residualOnly: true
})
);
Expand Down
Loading