Skip to content

Commit

Permalink
Merge pull request #347 from cdk/patch/18Jul17
Browse files Browse the repository at this point in the history
Looks good. One minor question.
  • Loading branch information
egonw committed Jul 20, 2017
2 parents fea5589 + 7efbb65 commit 73b4cc8
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 18 deletions.
Expand Up @@ -493,6 +493,8 @@ private static boolean isDigit(char c) {

private static boolean isUnsignedInt(String str) {
int pos = 0;
if (str == null)
return false;
int len = str.length();
while (pos < len)
if (!isDigit(str.charAt(pos++)))
Expand Down
Expand Up @@ -1343,21 +1343,28 @@ static boolean isPseudoElement(final String symbol) {
* @return the specified value
* @throws CDKException the coordinates specification was not valid
*/
static double readMDLCoordinate(final String line, int offset) throws CDKException {
double readMDLCoordinate(final String line, int offset) throws CDKException {
// to be valid the decimal should be at the fifth index (4 sig fig)
if (line.charAt(offset + 5) != '.') throw new CDKException("invalid coordinate specification");

int start = offset;
while (line.charAt(start) == ' ')
start++;

int sign = sign(line.charAt(start));
if (sign < 0) start++;

int integral = readUInt(line, start, (offset + 5) - start);
int fraction = readUInt(line, offset + 6, 4);

return sign * (integral * 10000l + fraction) / 10000d;
if (line.charAt(offset + 5) != '.') {
handleError("Bad coordinate format specified, expected 4 decimal places: " + line.substring(offset));
int start = offset;
int end = offset;
while (line.charAt(start) == ' ')
start++;
end = start;
while (line.charAt(end) != ' ')
end++;
return Double.parseDouble(line.substring(start, end));
} else {
int start = offset;
while (line.charAt(start) == ' ')
start++;
int sign = sign(line.charAt(start));
if (sign < 0) start++;
int integral = readUInt(line, start, (offset + 5) - start);
int fraction = readUInt(line, offset + 6, 4);
return sign * (integral * 10000L + fraction) / 10000d;
}
}

/**
Expand Down
Expand Up @@ -1037,7 +1037,10 @@ protected static String formatMDLFloat(float fl) {
nf.setMinimumFractionDigits(4);
nf.setMaximumFractionDigits(4);
nf.setGroupingUsed(false);
s = nf.format(fl);
if (Double.isNaN(fl) || Double.isInfinite(fl))
s = "0.0000";
else
s = nf.format(fl);
l = 10 - s.length();
for (int f = 0; f < l; f++)
fs += " ";
Expand Down
Expand Up @@ -26,6 +26,7 @@

import org.junit.Test;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
Expand Down Expand Up @@ -267,17 +268,31 @@ public void invalidAtomSymbol() throws Exception {

@Test
public void readMDLCoordinate() throws Exception {
assertThat(MDLV2000Reader.readMDLCoordinate(" 7.8089", 0), is(closeTo(7.8089, 0.1)));
assertThat(new MDLV2000Reader().readMDLCoordinate(" 7.8089", 0), is(closeTo(7.8089, 0.1)));
}

@Test
public void readMDLCoordinate_negative() throws Exception {
assertThat(MDLV2000Reader.readMDLCoordinate(" -2.0012", 0), is(closeTo(-2.0012, 0.1)));
assertThat(new MDLV2000Reader().readMDLCoordinate(" -2.0012", 0), is(closeTo(-2.0012, 0.1)));
}

@Test
public void readMDLCoordinate_offset() throws Exception {
assertThat(MDLV2000Reader.readMDLCoordinate(" -2.0012 7.8089", 10), is(closeTo(7.8089, 0.1)));
assertThat(new MDLV2000Reader().readMDLCoordinate(" -2.0012 7.8089", 10), is(closeTo(7.8089, 0.1)));
}

@Test
public void readOldJmolCoords() throws Exception {
MDLV2000Reader reader = new MDLV2000Reader();
reader.setReaderMode(IChemObjectReader.Mode.RELAXED);
assertThat(reader.readMDLCoordinate(" -2.00120 7.8089", 0), is(closeTo(-2.00120, 0.1)));
}

@Test(expected = CDKException.class)
public void readOldJmolCoordsFailOnStrictRead() throws Exception {
MDLV2000Reader reader = new MDLV2000Reader();
reader.setReaderMode(IChemObjectReader.Mode.STRICT);
reader.readMDLCoordinate(" -2.00120 7.8089", 0);
}

}
Expand Up @@ -126,6 +126,10 @@ public void distributePartners(IAtom atom, IAtomContainer placedNeighbours, Poin
Vector2d newDirection = new Vector2d(atom.getPoint2d());
Vector2d occupiedDirection = new Vector2d(sharedAtomsCenter);
occupiedDirection.sub(newDirection);
// if the placing on the centre atom we get NaNs just give a arbitary direciton the
// rest works it's self out
if (Math.abs(occupiedDirection.length()) < 0.001)
occupiedDirection = new Vector2d(0, 1);
logger.debug("distributePartners->occupiedDirection.lenght(): " + occupiedDirection.length());
List<IAtom> atomsToDraw = new ArrayList<IAtom>();

Expand Down
Expand Up @@ -2,3 +2,4 @@ C1CC2CC1CC3CCC4CC5CCC(C5)CC6CCC(C2)C6CC34 |(2.66,3.73,;3.67,2.74,;2.95,1.35,;1.5
C12C3C4C5C1[Fe]23456789C%10C9C8C7C%106 |(.57,5.08,;-1.03,5.08,;-1.54,4.13,;-.27,3.41,;1.04,4.13,;-.27,2.8,;.55,2.17,;-1.05,2.17,;-1.57,1.23,;-.29,.5,;1.02,1.23,)|
C1CCC2C(C1)CC3CC2C4C5CCC6(CCCC7CCCCC76)CCCC(C4C3)C8C9CCCC9CCC58 |(-5.68,12.41,;-6.98,13.16,;-8.28,12.41,;-8.28,10.91,;-6.98,10.16,;-5.68,10.91,;-6.98,8.66,;-8.28,7.91,;-8.28,9.41,;-9.58,10.16,;-10.88,9.41,;-12.17,10.16,;-11.32,10.98,;-11.33,12.32,;-12.35,13.09,;-11.06,13.84,;-11.06,15.34,;-12.35,16.09,;-13.65,15.34,;-14.95,16.09,;-16.25,15.34,;-16.25,13.84,;-14.95,13.09,;-13.65,13.84,;-13.42,12.32,;-13.42,10.82,;-12.14,8.95,;-12.17,7.16,;-10.88,7.91,;-9.58,7.16,;-13.47,7.91,;-14.77,7.16,;-15.08,5.69,;-16.58,5.53,;-17.19,6.9,;-16.07,7.91,;-16.07,9.41,;-14.77,10.16,;-13.47,9.41,)|
C1CC2CCC1CCC3CCC(CC2)CC3 |(-8.98,3.83,;-8.98,2.33,;-7.68,1.58,;-6.38,2.33,;-6.38,3.83,;-7.68,4.58,;-7.68,6.08,;-3.59,6.08,;-3.59,4.58,;-2.29,3.83,;-2.29,2.33,;-3.59,1.58,;-3.59,0.08,;-7.68,0.08,;-4.88,2.33,;-4.88,3.83,)|
C1CCC2CCC3CCCCC4CCC(C1)C243 |(3.8,-0.77,;3.8,0.78,;2.46,1.56,;1.14,0.83,;0.71,2.17,;-0.7,2.17,;-1.13,0.83,;-2.46,1.56,;-3.8,0.78,;-3.8,-0.77,;-2.46,-1.54,;-1.13,-0.83,;-0.7,-2.17,;0.71,-2.17,;1.14,-0.83,;2.46,-1.54,;0.01,0.00,)|
Expand Up @@ -10,6 +10,7 @@ C1CCCCCCCCC1 |(-1.88,-1.2,;-2.63,0.1,;-1.88,1.4,;-0.37,1.4,;0.38,2.7,;1.88,2.7,;
C1CCCCCCCCC1 |(-1.53,5.42,;-0.06,5.69,;1.07,4.7,;2.52,5.1,;3.35,3.85,;2.41,2.67,;1.01,3.2,;-0.21,2.32,;-1.65,2.72,;-2.24,4.1,)|
C1CCCCCCCCC1 |(2.38,2.6,;3.82,3.04,;5.24,2.54,;6.09,1.31,;6.06,-0.19,;5.16,-1.38,;3.72,-1.82,;2.31,-1.33,;1.45,-0.1,;1.48,1.4,)|
C1CCCCCCCCCCC1 |(-3.19,1.55,;-2.44,0.25,;-0.94,0.25,;-0.19,-1.05,;1.31,-1.05,;2.06,0.25,;1.31,1.55,;2.06,2.85,;1.31,4.15,;-0.19,4.15,;-0.94,2.85,;-2.44,2.85,)| 12 3 1 3
C1CCCCCCCCCCC1 |(-7.68,1.58,;-6.38,2.33,;-6.38,3.83,;-7.68,4.58,;-7.68,6.08,;-3.59,6.08,;-3.59,4.58,;-4.88,3.83,;-4.88,2.33,;-3.59,1.58,;-3.59,0.08,;-7.68,0.08,)|
C1CCCCCCCCCCCCC1 |(3.1,1.87,;2.35,0.58,;0.85,0.58,;0.1,-0.72,;-1.4,-0.72,;-2.15,0.58,;-3.65,0.58,;-4.4,1.88,;-3.65,3.17,;-2.15,3.17,;-1.4,4.47,;0.1,4.47,;0.85,3.17,;2.35,3.17,)| 14 2 2 5
C1CCCCCCCCCCCCC1 |(-4.4,0.1,;-3.65,-1.2,;-2.15,-1.2,;-1.4,0.1,;0.1,0.1,;0.85,-1.2,;2.35,-1.2,;3.1,0.1,;2.35,1.4,;0.85,1.4,;0.1,2.7,;-1.4,2.7,;-2.15,1.4,;-3.65,1.4,)| 14 1 0 2
C1CCCCCCCCCCCCC1 |(2.6,1.5,;2.6,-0,;1.3,-0.75,;0,0,;-1.3,-0.75,;-2.6,-0,;-3.9,-0.75,;-5.2,-0,;-5.2,1.5,;-3.9,2.25,;-2.6,1.5,;-1.3,2.25,;0,1.5,;1.3,2.25,)| 14 1 0 2
Expand Down

0 comments on commit 73b4cc8

Please sign in to comment.