From 898d8296a7131afc877e13ea745ab2712e3d8966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 25 Jul 2024 12:01:55 +0200 Subject: [PATCH] fix: rxn v3 bug Refs: https://github.com/Actelion/openchemlib/issues/111 --- scripts/openchemlib/classes.js | 9 +++++++-- .../com/actelion/research/chem/TextDrawingObject.java | 4 +++- .../com/actelion/research/chem/io/RXNFileV3Creator.java | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/openchemlib/classes.js b/scripts/openchemlib/classes.js index c9bbb56a..b5626c6e 100644 --- a/scripts/openchemlib/classes.js +++ b/scripts/openchemlib/classes.js @@ -317,10 +317,15 @@ function changeTautomerHelper(code) { } function changeTextDrawingObject(code) { + code = replaceChecked( + code, + 'import java.util.ArrayList;', + 'import java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.util.ArrayList;', + ); return replaceChecked( code, String.raw`detail.append(String.format(" size=\"%.4f\"", new Double(mSize)));`, - String.raw`detail.append(" size=\""+mSize+"\"");`, + String.raw`detail.append(" size=\""+new BigDecimal(mSize, new MathContext(4)).toString()+"\"");`, ); } @@ -365,7 +370,7 @@ function removeRXNStringFormat(code) { return replaceChecked( code, 'theWriter.write(String.format("M V30 COUNTS %d %d"+NL,rcnt,pcnt));', - 'theWriter.write("M V30 COUNTS "+rcnt+" "+pcnt+NL,rcnt,pcnt);', + 'theWriter.write("M V30 COUNTS "+rcnt+" "+pcnt+NL);', ); } diff --git a/src/com/actelion/research/gwt/chemlib/com/actelion/research/chem/TextDrawingObject.java b/src/com/actelion/research/gwt/chemlib/com/actelion/research/chem/TextDrawingObject.java index 84bd2691..97f85877 100644 --- a/src/com/actelion/research/gwt/chemlib/com/actelion/research/chem/TextDrawingObject.java +++ b/src/com/actelion/research/gwt/chemlib/com/actelion/research/chem/TextDrawingObject.java @@ -38,6 +38,8 @@ import com.actelion.research.gui.generic.GenericRectangle; import java.awt.*; +import java.math.BigDecimal; +import java.math.MathContext; import java.util.ArrayList; public class TextDrawingObject extends AbstractDrawingObject { @@ -145,7 +147,7 @@ public String getDescriptorDetail() { detail.append(" x=\""+mPoint[0].x + "\""); detail.append(" y=\""+mPoint[0].y + "\""); if (mSize != DEFAULT_SIZE) - detail.append(" size=\""+mSize+"\""); + detail.append(" size=\""+new BigDecimal(mSize, new MathContext(4)).toString()+"\""); if (mStyle != DEFAULT_STYLE) detail.append(" style=\""+mStyle+ "\""); diff --git a/src/com/actelion/research/gwt/chemlib/com/actelion/research/chem/io/RXNFileV3Creator.java b/src/com/actelion/research/gwt/chemlib/com/actelion/research/chem/io/RXNFileV3Creator.java index 8da38551..89d799bc 100644 --- a/src/com/actelion/research/gwt/chemlib/com/actelion/research/chem/io/RXNFileV3Creator.java +++ b/src/com/actelion/research/gwt/chemlib/com/actelion/research/chem/io/RXNFileV3Creator.java @@ -71,7 +71,7 @@ public RXNFileV3Creator(Reaction r, String programName) { theWriter.write(NL); int rcnt = rxn.getReactants(); int pcnt = rxn.getProducts(); - theWriter.write("M V30 COUNTS "+rcnt+" "+pcnt+NL,rcnt,pcnt); + theWriter.write("M V30 COUNTS "+rcnt+" "+pcnt+NL); double scalingFactor = getScalingFactor(rxn);