Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
thsa committed Jul 15, 2024
1 parent eafbb27 commit 7163b49
Showing 1 changed file with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void neglectSpaceDelimitedCoordinates() {
* @return
*/
public StereoMolecule getCompactMolecule(String idcode) {
return (idcode == null || idcode.length() == 0) ? null : getCompactMolecule(idcode.getBytes(StandardCharsets.UTF_8), null);
return (idcode == null || idcode.isEmpty()) ? null : getCompactMolecule(idcode.getBytes(StandardCharsets.UTF_8), null);
}

/**
Expand Down Expand Up @@ -151,7 +151,7 @@ public StereoMolecule getCompactMolecule(byte[] idcode, byte[] coordinates, int
* @param idcode null or idcode, which may contain coordinates separated by a space character
*/
public void parse(StereoMolecule mol, String idcode) {
if (idcode == null || idcode.length() == 0) {
if (idcode == null || idcode.isEmpty()) {
parse(mol, (byte[])null, (byte[])null);
return;
}
Expand Down Expand Up @@ -437,9 +437,10 @@ public void parse(StereoMolecule mol, byte[] idcode, byte[] coordinates, int idc
int offset = 0;
while (decodeBits(1) == 1) {
int dataType = offset + decodeBits(4);
int no;
switch (dataType) {
case 0: // datatype 'AtomQFNoMoreNeighbours'
int no = decodeBits(abits);
no = decodeBits(abits);
for (int i=0; i<no; i++) {
int atom = decodeBits(abits);
mMol.setAtomQueryFeature(atom, Molecule.cAtomQFNoMoreNeighbours, true);
Expand Down Expand Up @@ -762,10 +763,10 @@ public void parse(StereoMolecule mol, byte[] idcode, byte[] coordinates, int idc
from = 0;
factor = 8.0;
}
mMol.setAtomX(atom, mMol.getAtomX(from) + factor * (decodeBits(resolutionBits) - binCount / 2));
mMol.setAtomY(atom, mMol.getAtomY(from) + factor * (decodeBits(resolutionBits) - binCount / 2));
mMol.setAtomX(atom, mMol.getAtomX(from) + factor * (decodeBits(resolutionBits) - binCount / 2.0));
mMol.setAtomY(atom, mMol.getAtomY(from) + factor * (decodeBits(resolutionBits) - binCount / 2.0));
if (coordsAre3D)
mMol.setAtomZ(atom, mMol.getAtomZ(from) + factor * (decodeBits(resolutionBits) - binCount / 2));
mMol.setAtomZ(atom, mMol.getAtomZ(from) + factor * (decodeBits(resolutionBits) - binCount / 2.0));
}

if (coordinates[coordsStart] == '#') { // we have 3D-coordinates that include implicit hydrogen coordinates
Expand All @@ -781,10 +782,10 @@ public void parse(StereoMolecule mol, byte[] idcode, byte[] coordinates, int idc
int hydrogen = mMol.addAtom(1);
mMol.addBond(atom, hydrogen, Molecule.cBondTypeSingle);

mMol.setAtomX(hydrogen, mMol.getAtomX(atom) + (decodeBits(resolutionBits) - binCount / 2));
mMol.setAtomY(hydrogen, mMol.getAtomY(atom) + (decodeBits(resolutionBits) - binCount / 2));
mMol.setAtomX(hydrogen, mMol.getAtomX(atom) + (decodeBits(resolutionBits) - binCount / 2.0));
mMol.setAtomY(hydrogen, mMol.getAtomY(atom) + (decodeBits(resolutionBits) - binCount / 2.0));
if (coordsAre3D)
mMol.setAtomZ(hydrogen, mMol.getAtomZ(atom) + (decodeBits(resolutionBits) - binCount / 2));
mMol.setAtomZ(hydrogen, mMol.getAtomZ(atom) + (decodeBits(resolutionBits) - binCount / 2.0));
}
}

Expand Down Expand Up @@ -935,10 +936,10 @@ public void parseCoordinates(byte[] encodedCoords, int coordsStart, StereoMolecu
from = 0;
factor = 8.0;
}
coords[atom].x = coords[from].x + factor * (decodeBits(resolutionBits) - binCount / 2);
coords[atom].y = coords[from].y + factor * (decodeBits(resolutionBits) - binCount / 2);
coords[atom].x = coords[from].x + factor * (decodeBits(resolutionBits) - binCount / 2.0);
coords[atom].y = coords[from].y + factor * (decodeBits(resolutionBits) - binCount / 2.0);
if (coordsAre3D)
coords[atom].z = coords[from].z + factor * (decodeBits(resolutionBits) - binCount / 2);
coords[atom].z = coords[from].z + factor * (decodeBits(resolutionBits) - binCount / 2.0);
}

double avbl = coordsAre3D ? 1.5 : Molecule.getDefaultAverageBondLength();
Expand All @@ -954,10 +955,10 @@ public void parseCoordinates(byte[] encodedCoords, int coordsStart, StereoMolecu
for (int atom = 0; atom < atomCount; atom++) {
int hCount = mol.getAllConnAtoms(atom) - mol.getConnAtoms(atom);
for (int i = 0; i < hCount; i++) {
coords[hydrogen].x = coords[atom].x + (decodeBits(resolutionBits) - binCount / 2);
coords[hydrogen].y = coords[atom].y + (decodeBits(resolutionBits) - binCount / 2);
coords[hydrogen].x = coords[atom].x + (decodeBits(resolutionBits) - binCount / 2.0);
coords[hydrogen].y = coords[atom].y + (decodeBits(resolutionBits) - binCount / 2.0);
if (coordsAre3D)
coords[hydrogen].z = coords[atom].z + (decodeBits(resolutionBits) - binCount / 2);
coords[hydrogen].z = coords[atom].z + (decodeBits(resolutionBits) - binCount / 2.0);

hydrogen++;
}
Expand Down Expand Up @@ -1072,7 +1073,7 @@ else if (coordinates[coordStart] == '!' || coordinates[coordStart] == '#') {
}

public int getIDCodeVersion(String idcode) {
if (idcode == null || idcode.length() == 0)
if (idcode == null || idcode.isEmpty())
return -1;

return getIDCodeVersion(idcode.getBytes(StandardCharsets.UTF_8));
Expand All @@ -1090,7 +1091,7 @@ public int getIDCodeVersion(byte[] idcode) {
}

public int getAtomCount(String idcode) {
if (idcode == null || idcode.length() == 0)
if (idcode == null || idcode.isEmpty())
return 0;

return getAtomCount(idcode.getBytes(StandardCharsets.UTF_8), 0);
Expand Down Expand Up @@ -1120,7 +1121,7 @@ public int getAtomCount(byte[] idcode, int offset) {
* @return int[] with atom and bond count as first and second values
*/
public int[] getAtomAndBondCounts(String idcode, int[] count) {
if (idcode == null || idcode.length() == 0)
if (idcode == null || idcode.isEmpty())
return null;

return getAtomAndBondCounts(idcode.getBytes(StandardCharsets.UTF_8), 0, count);
Expand Down Expand Up @@ -1192,7 +1193,7 @@ private double decodeShift(int value, int binCount) {
boolean isNegative = (value >= halfBinCount);
if (isNegative)
value -= halfBinCount;
double steepness = binCount/32;
double steepness = binCount/32.0;
double doubleValue = steepness * value / (halfBinCount - value);
return isNegative ? -doubleValue : doubleValue;
}
Expand Down Expand Up @@ -1366,9 +1367,10 @@ public void printContent(byte[] idcode, byte[] coordinates) {
int offset = 0;
while (decodeBits(1) == 1) {
int dataType = offset + decodeBits(4);
int no;
switch (dataType) {
case 0: // datatype 'AtomQFNoMoreNeighbours'
int no = decodeBits(abits);
no = decodeBits(abits);
System.out.print("noMoreNeighbours:");
for (int i = 0; i < no; i++)
System.out.print(" " + decodeBits(abits));
Expand Down Expand Up @@ -1675,12 +1677,12 @@ public void printContent(byte[] idcode, byte[] coordinates) {
factor = 8.0;
}
System.out.print(atom + " (");
coords[0][atom] = coords[0][from] + factor * (decodeBits(resolutionBits) - binCount / 2);
coords[0][atom] = coords[0][from] + factor * (decodeBits(resolutionBits) - binCount / 2.0);
System.out.print((int) coords[0][atom] + ",");
coords[1][atom] = coords[1][from] + factor * (decodeBits(resolutionBits) - binCount / 2);
coords[1][atom] = coords[1][from] + factor * (decodeBits(resolutionBits) - binCount / 2.0);
System.out.print((int) coords[1][atom]);
if (coordsAre3D) {
coords[2][atom] = coords[2][from] + factor * (decodeBits(resolutionBits) - binCount / 2);
coords[2][atom] = coords[2][from] + factor * (decodeBits(resolutionBits) - binCount / 2.0);
System.out.print("," + (int) coords[0][atom]);
}
System.out.print("), ");
Expand Down Expand Up @@ -1719,12 +1721,12 @@ public void printContent(byte[] idcode, byte[] coordinates) {
System.out.print(atom);
for (int i = 0; i < hCount[atom]; i++) {
System.out.print(" (");
coords[0][hydrogen] = coords[0][atom] + (decodeBits(resolutionBits) - binCount / 2);
coords[0][hydrogen] = coords[0][atom] + (decodeBits(resolutionBits) - binCount / 2.0);
System.out.print((int) coords[0][hydrogen] + ",");
coords[1][hydrogen] = coords[1][atom] + (decodeBits(resolutionBits) - binCount / 2);
coords[1][hydrogen] = coords[1][atom] + (decodeBits(resolutionBits) - binCount / 2.0);
System.out.print((int) coords[1][hydrogen]);
if (coordsAre3D) {
coords[2][hydrogen] = coords[2][atom] + (decodeBits(resolutionBits) - binCount / 2);
coords[2][hydrogen] = coords[2][atom] + (decodeBits(resolutionBits) - binCount / 2.0);
System.out.print("," + (int) coords[2][hydrogen]);
}
System.out.print("), ");
Expand Down

0 comments on commit 7163b49

Please sign in to comment.