Skip to content

Commit

Permalink
Pass in fixed bonds to layout refiner.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Jun 5, 2016
1 parent 3af1363 commit 2829ad5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,16 @@ final class LayoutRefiner {
// in the same ring system
private final int[] ringsystems;

private final Set<IBond> fixed;

/**
* Create a new layout refiner for the provided molecule.
*
* @param mol molecule to refine
*/
public LayoutRefiner(IAtomContainer mol) {
LayoutRefiner(IAtomContainer mol, Set<IBond> fixed) {
this.mol = mol;
this.fixed = fixed;
this.bondMap = GraphUtil.EdgeToBondMap.withSpaceFor(mol);
this.adjList = GraphUtil.toAdjList(mol, bondMap);
this.idxs = new HashMap<>();
Expand Down Expand Up @@ -333,6 +336,8 @@ void rotate(Collection<AtomPair> pairs) {
// only try each bond once per phase and skip
if (!tried.add(bond))
continue;
if (fixed.contains(bond))
continue;

// those we have found to probably be symmetric
if (probablySymmetric.contains(bond))
Expand Down Expand Up @@ -430,7 +435,8 @@ private boolean macroCycleInversion(AtomPair pair) {
continue;

for (IBond bond : acyclic) {

if (fixed.contains(bond))
continue;
Arrays.fill(visited, false);
stackBackup.len = visit(visited, stackBackup.xs, v, idxs.get(bond.getConnectedAtom(atom)), 0);

Expand Down Expand Up @@ -461,13 +467,16 @@ private boolean fusionPointInversion(AtomPair pair) {
// > 3 bonds
if (pair.bndAt.length != 3)
return false;
if (fixed.contains(pair.bndAt[0]) || fixed.contains(pair.bndAt[2]))
return false;
// we want *!@*@*!@*
if (!pair.bndAt[0].isInRing() || pair.bndAt[1].isInRing() || pair.bndAt[2].isInRing())
return false;
// non-terminals
if (adjList[pair.fst].length > 1 || adjList[pair.snd].length > 1)
return false;


IAtom fst = atoms[pair.fst];

// choose which one to invert, preffering hydrogens
Expand Down Expand Up @@ -510,6 +519,9 @@ private double bend(AtomPair pair, IntStack stack, Point2d[] coords, Map<IBond,A
final IBond bndA = pair.bndAt[2];
final IBond bndB = pair.bndAt[3];

if (fixed.contains(bndA) || fixed.contains(bndB))
return Integer.MAX_VALUE;

final IAtom pivotA = getCommon(bndA, pair.bndAt[1]);
final IAtom pivotB = getCommon(bndB, pair.bndAt[0]);

Expand Down Expand Up @@ -556,6 +568,7 @@ private double bend(AtomPair pair, IntStack stack, Point2d[] coords, Map<IBond,A
// try bending all bonds and accept the best one
for (IBond bond : pair.bndAt) {
if (bond.isInRing()) continue;
if (fixed.contains(bond)) continue;

// has this bond already been tested as part of another pair
AtomPair first = firstVisit.get(bond);
Expand Down Expand Up @@ -639,6 +652,7 @@ private double stretch(AtomPair pair, IntStack stack, Point2d[] coords, Map<IBon
// don't stretch ring bonds
if (bond.isInRing())
continue;
if (fixed.contains(bond)) continue;

// has this bond already been tested as part of another pair
AtomPair first = firstVisit.get(bond);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ private void refinePlacement(IAtomContainer molecule) {
AtomPlacer.prioritise(molecule);

// refine the layout by rotating, bending, and stretching bonds
LayoutRefiner refiner = new LayoutRefiner(molecule);
LayoutRefiner refiner = new LayoutRefiner(molecule, bfix);
refiner.refine();

// choose the orientation in which to display the structure
Expand Down

0 comments on commit 2829ad5

Please sign in to comment.