| 1 |
/** |
| 2 |
* JNA-RInChI - Library for calling RInChI from Java |
| 3 |
* Copyright © 2022 Nikolay Kochev |
| 4 |
* <p> |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* <p> |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU Lesser General Public License for more details. |
| 14 |
* <p> |
| 15 |
* You should have received a copy of the GNU Lesser General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
package io.github.dan2097.jnarinchi; |
| 19 |
|
| 20 |
import org.junit.jupiter.api.Assertions; |
| 21 |
import org.junit.jupiter.api.DisplayName; |
| 22 |
import org.junit.jupiter.api.Test; |
| 23 |
|
| 24 |
import java.io.IOException; |
| 25 |
import java.io.InputStream; |
| 26 |
import java.util.ArrayList; |
| 27 |
import java.util.List; |
| 28 |
import java.util.Properties; |
| 29 |
|
| 30 |
import static org.junit.jupiter.api.Assertions.*; |
| 31 |
|
| 32 |
/** |
| 33 |
* Testing the main functionality of the jna-rinchi-core module. |
| 34 |
* <br> |
| 35 |
* The testing data is provided by the IUPAC RInChI developers and available |
| 36 |
* at the <a href="https://github.com/IUPAC-InChI/RInChI">RInChI repository</a>. |
| 37 |
* @author Nikolay Kochev |
| 38 |
* @author Uli Fechner |
| 39 |
*/ |
| 40 |
class JnaRinchiTest { |
| 41 |
|
| 42 |
/** |
| 43 |
* Reading the full RInChI information from a text file. |
| 44 |
* The full RInChI information comprises the RInChI itself, RAuxInfo, Long-RInChIKey, Short-RInChIKey and Web-RInChIKey. |
| 45 |
* |
| 46 |
* @param fileName text file name containing the full RInChI information |
| 47 |
* @return RinchiFullInfo object with the full RInChI information |
| 48 |
*/ |
| 49 |
static RinchiFullInfo readRinchiFullInfoFromResourceFile(String fileName) throws IOException { |
| 50 |
InputStream is = JnaRinchiTest.class.getResourceAsStream(fileName); |
| 51 |
Properties props = new Properties(); |
| 52 |
props.load(is); |
| 53 |
is.close(); |
| 54 |
|
| 55 |
RinchiFullInfo rfi = new RinchiFullInfo(); |
| 56 |
if (props.containsKey("RInChI")) { |
| 57 |
rfi.setRinchi("RInChI=" + props.getProperty("RInChI")); |
| 58 |
} |
| 59 |
if (props.containsKey("RAuxInfo")) { |
| 60 |
rfi.setAuxInfo("RAuxInfo=" + props.getProperty("RAuxInfo")); |
| 61 |
} |
| 62 |
if (props.containsKey("Long-RInChIKey")) { |
| 63 |
rfi.setRinchiKeyLong("Long-RInChIKey=" + props.getProperty("Long-RInChIKey")); |
| 64 |
} |
| 65 |
if (props.containsKey("Short-RInChIKey")) { |
| 66 |
rfi.setRinchiKeyShort("Short-RInChIKey=" + props.getProperty("Short-RInChIKey")); |
| 67 |
} |
| 68 |
if (props.containsKey("Web-RInChIKey")) { |
| 69 |
rfi.setRinchiKeyWeb("Web-RInChIKey=" + props.getProperty("Web-RInChIKey")); |
| 70 |
} |
| 71 |
|
| 72 |
return rfi; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Generic test that compares the <i>generated</i> RInChI, RAuxInfo and the three RInChI-Keys with the <i>expected</i> data. |
| 77 |
* <br> |
| 78 |
* If RAuxInfo, Long-RInChI-Keys, Short-RInChI-Keys or Web-RInChI-Keys are not supplied in the text file |
| 79 |
* that contains the expected data, it is excluded from the comparison. For example, if there is no line |
| 80 |
* starting with {@code Long-RInChIKey=} in the text file with the expected data, the generated Long-RInChIKey |
| 81 |
* is excluded from comparing the actual to the expected data. The test still fails if the generation of |
| 82 |
* the excluded data point gives raise to an error. |
| 83 |
* <br> |
| 84 |
* The calculation of the RInChI is carried out with the default options as specified in |
| 85 |
* {@link RinchiOptions#DEFAULT_OPTIONS} which has set forceEquilibrium to <code>false</code>. |
| 86 |
* |
| 87 |
* @param reactionFile the reaction text file in RXN or RDFile format |
| 88 |
* @param rinchiFile text file with all RInCHI information |
| 89 |
*/ |
| 90 |
static void genericExampleTest(String reactionFile, String rinchiFile) throws IOException { |
| 91 |
String reactText = TestUtils.readTextFromResourceAsString(reactionFile); |
| 92 |
assertNotNull(reactText, "Reading reaction from text file " + reactionFile); |
| 93 |
RinchiFullInfo rfi = readRinchiFullInfoFromResourceFile(rinchiFile); |
| 94 |
assertNotNull(rfi, "Reading Rinchi Full Information from file " + rinchiFile); |
| 95 |
|
| 96 |
RinchiOutput rinchiOut; |
| 97 |
RinchiKeyOutput rinchiKeyOut; |
| 98 |
|
| 99 |
//Generate RInChI from text file |
| 100 |
//RInChI examples works with option: forceEquilibrium = false (which is by default); |
| 101 |
rinchiOut = JnaRinchi.fileTextToRinchi(reactText); |
| 102 |
assertEquals(rfi.getRinchi(), rinchiOut.getRinchi(), "Rinchi for " + reactionFile); |
| 103 |
|
| 104 |
if (rfi.getAuxInfo() != null) { |
| 105 |
assertEquals(rfi.getAuxInfo(), rinchiOut.getAuxInfo(), "RAuxInfo for " + reactionFile); |
| 106 |
} |
| 107 |
|
| 108 |
//Generate Long-RinchiKey from text file |
| 109 |
rinchiKeyOut = JnaRinchi.fileTextToRinchiKey(reactText, RinchiKeyType.LONG); |
| 110 |
if (rfi.getRinchiKeyLong() != null) { |
| 111 |
assertEquals(rfi.getRinchiKeyLong(), rinchiKeyOut.getRinchiKey(), "Long-RinchiKey for " + reactionFile); |
| 112 |
} |
| 113 |
|
| 114 |
//Generate Short-RinchiKey from text file |
| 115 |
rinchiKeyOut = JnaRinchi.fileTextToRinchiKey(reactText, RinchiKeyType.SHORT); |
| 116 |
if (rfi.getRinchiKeyShort() != null) { |
| 117 |
assertEquals(rfi.getRinchiKeyShort(), rinchiKeyOut.getRinchiKey(), "Short-RinchiKey for " + reactionFile); |
| 118 |
} |
| 119 |
|
| 120 |
//Generate Web-RinchiKey from text file |
| 121 |
rinchiKeyOut = JnaRinchi.fileTextToRinchiKey(reactText, RinchiKeyType.WEB); |
| 122 |
if (rfi.getRinchiKeyWeb() != null) { |
| 123 |
assertEquals(rfi.getRinchiKeyWeb(), rinchiKeyOut.getRinchiKey(), "Web-RinchiKey for " + reactionFile); |
| 124 |
} |
| 125 |
|
| 126 |
//Generate Long-RinchiKey from RInChI |
| 127 |
rinchiKeyOut = JnaRinchi.rinchiToRinchiKey(RinchiKeyType.LONG, rinchiOut.getRinchi()); |
| 128 |
if (rfi.getRinchiKeyLong() != null) { |
| 129 |
assertEquals(rfi.getRinchiKeyLong(), rinchiKeyOut.getRinchiKey(), "Long-RinchiKey for " + reactionFile |
| 130 |
+ " generated from RInChI"); |
| 131 |
} |
| 132 |
|
| 133 |
//Generate Short-RinchiKey from RInChI |
| 134 |
rinchiKeyOut = JnaRinchi.rinchiToRinchiKey(RinchiKeyType.SHORT, rinchiOut.getRinchi()); |
| 135 |
if (rfi.getRinchiKeyShort() != null) { |
| 136 |
assertEquals(rfi.getRinchiKeyShort(), rinchiKeyOut.getRinchiKey(), "Short-RinchiKey for " + reactionFile |
| 137 |
+ " generated from RInChI"); |
| 138 |
} |
| 139 |
|
| 140 |
//Generate Web-RinchiKey from RInChI |
| 141 |
rinchiKeyOut = JnaRinchi.rinchiToRinchiKey(RinchiKeyType.WEB, rinchiOut.getRinchi()); |
| 142 |
if (rfi.getRinchiKeyWeb() != null) { |
| 143 |
assertEquals(rfi.getRinchiKeyWeb(), rinchiKeyOut.getRinchiKey(), "Web-RinchiKey for " + reactionFile |
| 144 |
+ " generated from RInChI"); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Performs round-trip testing of the conversion from RInChI to MDL RXN/RDFile and vice versa. |
| 150 |
* |
| 151 |
* @param reactionFile the reaction text file in RXN or RDFile format |
| 152 |
* @param rinchiFile text file with all RInChI information |
| 153 |
* @param format format of the reaction file |
| 154 |
*/ |
| 155 |
static void doubleConversionExampleTest(String reactionFile, String rinchiFile, ReactionFileFormat format) throws IOException { |
| 156 |
//Double conversion test RIChI --> file text --> RInChI |
| 157 |
String reactText = TestUtils.readTextFromResourceAsString(reactionFile); |
| 158 |
assertNotNull(reactText, "Reading reaction from text file " + reactionFile); |
| 159 |
RinchiFullInfo rfi = readRinchiFullInfoFromResourceFile(rinchiFile); |
| 160 |
assertNotNull(rfi, "Reading Rinchi Full Infor from file " + rinchiFile); |
| 161 |
|
| 162 |
RinchiOutput rinchiOut0, rinchiOut; |
| 163 |
|
| 164 |
FileTextOutput fileTextOut = JnaRinchi.rinchiToFileText(rfi.getRinchi(), rfi.getAuxInfo(), format); |
| 165 |
assertSame(fileTextOut.getStatus(), Status.SUCCESS, "RIChI to FileText conversion status for " + rinchiFile); |
| 166 |
rinchiOut = JnaRinchi.fileTextToRinchi(fileTextOut.getReactionFileText()); |
| 167 |
assertEquals(rfi.getRinchi(), rinchiOut.getRinchi(), "Rinchi for " + reactionFile); |
| 168 |
assertEquals(rfi.getAuxInfo(), rinchiOut.getAuxInfo(), "RAuxInfo for " + reactionFile); |
| 169 |
|
| 170 |
//Testing number of components and decomposed InChIs |
| 171 |
rinchiOut0 = JnaRinchi.fileTextToRinchi(reactText); |
| 172 |
assertEquals(rinchiOut0.getRinchi(), rinchiOut.getRinchi(), "Rinchi for " + reactionFile); |
| 173 |
assertEquals(rinchiOut0.getAuxInfo(), rinchiOut.getAuxInfo(), "RAuxInfo for " + reactionFile); |
| 174 |
} |
| 175 |
|
| 176 |
@Test |
| 177 |
void test_getRinchiLibraryVersion() { |
| 178 |
assertEquals("1.00", JnaRinchi.getRinchiLibraryVersion()); |
| 179 |
} |
| 180 |
|
| 181 |
@Test |
| 182 |
void testCheckLibrary() { |
| 183 |
// if the native library cannot be loaded a RuntimeException is thrown, and we fail this test |
| 184 |
try { |
| 185 |
JnaRinchi.checkLibrary(); |
| 186 |
} catch(Exception exception) { |
| 187 |
Assertions.fail(exception); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
@Test |
| 192 |
void testExample_1_reactant_A() throws IOException { |
| 193 |
genericExampleTest("examples/1_reactant_-_A.rxn", "examples/1_reactant_-_A.txt"); |
| 194 |
doubleConversionExampleTest("examples/1_reactant_-_A.rxn", "examples/1_reactant_-_A.txt", ReactionFileFormat.RXN); |
| 195 |
doubleConversionExampleTest("examples/1_reactant_-_A.rxn", "examples/1_reactant_-_A.txt", ReactionFileFormat.RD); |
| 196 |
} |
| 197 |
|
| 198 |
@Test |
| 199 |
public void testExample_1_reactant_no_product() throws IOException { |
| 200 |
genericExampleTest("examples/1_reactant_-_no_product.rxn", "examples/1_reactant_-_no_product.txt"); |
| 201 |
doubleConversionExampleTest("examples/1_reactant_-_no_product.rxn", "examples/1_reactant_-_no_product.txt", ReactionFileFormat.RXN); |
| 202 |
doubleConversionExampleTest("examples/1_reactant_-_no_product.rxn", "examples/1_reactant_-_no_product.txt", ReactionFileFormat.RD); |
| 203 |
} |
| 204 |
|
| 205 |
@Test |
| 206 |
public void testExample_1_reactant_no_structure() throws IOException { |
| 207 |
genericExampleTest("examples/1_reactant_-_no_structure.rxn", "examples/1_reactant_-_no_structure.txt"); |
| 208 |
doubleConversionExampleTest("examples/1_reactant_-_no_structure.rxn", "examples/1_reactant_-_no_structure.txt", ReactionFileFormat.RXN); |
| 209 |
doubleConversionExampleTest("examples/1_reactant_-_no_structure.rxn", "examples/1_reactant_-_no_structure.txt", ReactionFileFormat.RD); |
| 210 |
} |
| 211 |
|
| 212 |
@Test |
| 213 |
public void testExample_1_reactant_R() throws IOException { |
| 214 |
genericExampleTest("examples/1_reactant_-_R.rxn", "examples/1_reactant_-_R.txt"); |
| 215 |
doubleConversionExampleTest("examples/1_reactant_-_R.rxn", "examples/1_reactant_-_R.txt", ReactionFileFormat.RXN); |
| 216 |
doubleConversionExampleTest("examples/1_reactant_-_R.rxn", "examples/1_reactant_-_R.txt", ReactionFileFormat.RD); |
| 217 |
} |
| 218 |
|
| 219 |
@Test |
| 220 |
public void testExample_1_reactant_X() throws IOException { |
| 221 |
genericExampleTest("examples/1_reactant_-_X.rxn", "examples/1_reactant_-_X.txt"); |
| 222 |
doubleConversionExampleTest("examples/1_reactant_-_X.rxn", "examples/1_reactant_-_X.txt", ReactionFileFormat.RXN); |
| 223 |
doubleConversionExampleTest("examples/1_reactant_-_X.rxn", "examples/1_reactant_-_X.txt", ReactionFileFormat.RD); |
| 224 |
} |
| 225 |
|
| 226 |
@Test |
| 227 |
public void testExample_Esterification_01_flat() throws IOException { |
| 228 |
genericExampleTest("examples/Esterification_01_flat.rdf", "examples/Esterification_01_flat.txt"); |
| 229 |
//Double conversion with RXN format fails! |
| 230 |
//doubleConversionExampleTest("examples/Esterification_01_flat.rdf", "examples/Esterification_01_flat.txt", ReactionFileFormat.RXN); |
| 231 |
doubleConversionExampleTest("examples/Esterification_01_flat.rdf", "examples/Esterification_01_flat.txt", ReactionFileFormat.RD); |
| 232 |
} |
| 233 |
|
| 234 |
@Test |
| 235 |
public void testExample_Esterification_01() throws IOException { |
| 236 |
genericExampleTest("examples/Esterification_01.rdf", "examples/Esterification_01.txt"); |
| 237 |
//Double conversion with RXN format fails! |
| 238 |
//doubleConversionExampleTest("examples/Esterification_01.rdf", "examples/Esterification_01.txt", ReactionFileFormat.RXN); |
| 239 |
doubleConversionExampleTest("examples/Esterification_01.rdf", "examples/Esterification_01.txt", ReactionFileFormat.RD); |
| 240 |
} |
| 241 |
|
| 242 |
@Test |
| 243 |
public void testExample_Esterification_02() throws IOException { |
| 244 |
genericExampleTest("examples/Esterification_02.rdf", "examples/Esterification_02.txt"); |
| 245 |
//Double conversion with RXN format fails! |
| 246 |
//doubleConversionExampleTest("examples/Esterification_02.rdf", "examples/Esterification_02.txt", ReactionFileFormat.RXN); |
| 247 |
doubleConversionExampleTest("examples/Esterification_02.rdf", "examples/Esterification_02.txt", ReactionFileFormat.RD); |
| 248 |
} |
| 249 |
|
| 250 |
@Test |
| 251 |
public void testExample_Esterification_03() throws IOException { |
| 252 |
genericExampleTest("examples/Esterification_03.rdf", "examples/Esterification_03.txt"); |
| 253 |
//Double conversion with RXN format fails! |
| 254 |
//doubleConversionExampleTest("examples/Esterification_03.rdf", "examples/Esterification_03.txt", ReactionFileFormat.RXN); |
| 255 |
doubleConversionExampleTest("examples/Esterification_03.rdf", "examples/Esterification_03.txt", ReactionFileFormat.RD); |
| 256 |
} |
| 257 |
|
| 258 |
@Test |
| 259 |
public void testExample_Inverted_stereochemistry() throws IOException { |
| 260 |
genericExampleTest("examples/Inverted_stereochemistry.rxn", "examples/Inverted_stereochemistry.txt"); |
| 261 |
doubleConversionExampleTest("examples/Inverted_stereochemistry.rxn", "examples/Inverted_stereochemistry.txt", ReactionFileFormat.RXN); |
| 262 |
doubleConversionExampleTest("examples/Inverted_stereochemistry.rxn", "examples/Inverted_stereochemistry.txt", ReactionFileFormat.RD); |
| 263 |
} |
| 264 |
|
| 265 |
@Test |
| 266 |
public void testExample_Multiplesteps() throws IOException { |
| 267 |
genericExampleTest("examples/Multiplesteps.rdf", "examples/Multiplesteps.txt"); |
| 268 |
//Double conversion with RXN format fails! |
| 269 |
//doubleConversionExampleTest("examples/Multiplesteps.rdf", "examples/Multiplesteps.txt", ReactionFileFormat.RXN); |
| 270 |
doubleConversionExampleTest("examples/Multiplesteps.rdf", "examples/Multiplesteps.txt", ReactionFileFormat.RD); |
| 271 |
} |
| 272 |
|
| 273 |
@Test |
| 274 |
public void testExample_No_reactant_1_product_02() throws IOException { |
| 275 |
genericExampleTest("examples/No_reactant_-_1_product_02.rxn", "examples/No_reactant_-_1_product_02.txt"); |
| 276 |
doubleConversionExampleTest("examples/No_reactant_-_1_product_02.rxn", "examples/No_reactant_-_1_product_02.txt", ReactionFileFormat.RXN); |
| 277 |
doubleConversionExampleTest("examples/No_reactant_-_1_product_02.rxn", "examples/No_reactant_-_1_product_02.txt", ReactionFileFormat.RD); |
| 278 |
} |
| 279 |
|
| 280 |
@Test |
| 281 |
public void testExample_No_reactant_1_product() throws IOException { |
| 282 |
genericExampleTest("examples/No_reactant_-_1_product.rxn", "examples/No_reactant_-_1_product.txt"); |
| 283 |
doubleConversionExampleTest("examples/No_reactant_-_1_product.rxn", "examples/No_reactant_-_1_product.txt", ReactionFileFormat.RXN); |
| 284 |
doubleConversionExampleTest("examples/No_reactant_-_1_product.rxn", "examples/No_reactant_-_1_product.txt", ReactionFileFormat.RD); |
| 285 |
} |
| 286 |
|
| 287 |
@Test |
| 288 |
public void testExample_No_reactant_no_product() throws IOException { |
| 289 |
genericExampleTest("examples/No_reactant_-_no_product.rdf", "examples/No_reactant_-_no_product.txt"); |
| 290 |
//Double conversion with RXN format fails! |
| 291 |
//doubleConversionExampleTest("examples/No_reactant_-_no_product.rdf", "examples/No_reactant_-_no_product.txt", ReactionFileFormat.RXN); |
| 292 |
doubleConversionExampleTest("examples/No_reactant_-_no_product.rdf", "examples/No_reactant_-_no_product.txt", ReactionFileFormat.RD); |
| 293 |
} |
| 294 |
|
| 295 |
@Test |
| 296 |
public void testExample_no_structure_1_product() throws IOException { |
| 297 |
genericExampleTest("examples/no_structure_-_1_product.rxn", "examples/no_structure_-_1_product.txt"); |
| 298 |
doubleConversionExampleTest("examples/no_structure_-_1_product.rxn", "examples/no_structure_-_1_product.txt", ReactionFileFormat.RXN); |
| 299 |
doubleConversionExampleTest("examples/no_structure_-_1_product.rxn", "examples/no_structure_-_1_product.txt", ReactionFileFormat.RD); |
| 300 |
} |
| 301 |
|
| 302 |
@Test |
| 303 |
public void testExample_No_Structure_0_02() throws IOException { |
| 304 |
genericExampleTest("examples/No_Structure_0-02.rdf", "examples/No_Structure_0-02.txt"); |
| 305 |
//Double conversion with RXN format fails! |
| 306 |
//doubleConversionExampleTest("examples/No_Structure_0-02.rdf", "examples/No_Structure_0-02.txt", ReactionFileFormat.RXN); |
| 307 |
doubleConversionExampleTest("examples/No_Structure_0-02.rdf", "examples/No_Structure_0-02.txt", ReactionFileFormat.RD); |
| 308 |
} |
| 309 |
|
| 310 |
@Test |
| 311 |
public void testExample_Nnostruct_X() throws IOException { |
| 312 |
genericExampleTest("examples/nostruct_-_X.rxn", "examples/nostruct_-_X.txt"); |
| 313 |
doubleConversionExampleTest("examples/nostruct_-_X.rxn", "examples/nostruct_-_X.txt", ReactionFileFormat.RXN); |
| 314 |
doubleConversionExampleTest("examples/nostruct_-_X.rxn", "examples/nostruct_-_X.txt", ReactionFileFormat.RD); |
| 315 |
} |
| 316 |
|
| 317 |
@Test |
| 318 |
public void testExample_R__A() throws IOException { |
| 319 |
genericExampleTest("examples/R-_-A.rxn", "examples/R-_-A.txt"); |
| 320 |
doubleConversionExampleTest("examples/R-_-A.rxn", "examples/R-_-A.txt", ReactionFileFormat.RXN); |
| 321 |
doubleConversionExampleTest("examples/R-_-A.rxn", "examples/R-_-A.txt", ReactionFileFormat.RD); |
| 322 |
} |
| 323 |
|
| 324 |
@Test |
| 325 |
public void testExample_RingOpening01() throws IOException { |
| 326 |
genericExampleTest("examples/RingOpening01.rxn", "examples/RingOpening01.txt"); |
| 327 |
doubleConversionExampleTest("examples/RingOpening01.rxn", "examples/RingOpening01.txt", ReactionFileFormat.RXN); |
| 328 |
doubleConversionExampleTest("examples/RingOpening01.rxn", "examples/RingOpening01.txt", ReactionFileFormat.RD); |
| 329 |
} |
| 330 |
|
| 331 |
@Test |
| 332 |
public void testExample_star_star__nostruct() throws IOException { |
| 333 |
genericExampleTest("examples/star_star_-_nostruct.rxn", "examples/star_star_-_nostruct.txt"); |
| 334 |
doubleConversionExampleTest("examples/star_star_-_nostruct.rxn", "examples/star_star_-_nostruct.txt", ReactionFileFormat.RXN); |
| 335 |
doubleConversionExampleTest("examples/star_star_-_nostruct.rxn", "examples/star_star_-_nostruct.txt", ReactionFileFormat.RD); |
| 336 |
} |
| 337 |
|
| 338 |
@Test |
| 339 |
public void testExample_Styrene__Polystyrene_as_no_struct() throws IOException { |
| 340 |
genericExampleTest("examples/Styrene_-_Polystyrene_as_no-struct.rxn", "examples/Styrene_-_Polystyrene_as_no-struct.txt"); |
| 341 |
doubleConversionExampleTest("examples/Styrene_-_Polystyrene_as_no-struct.rxn", "examples/Styrene_-_Polystyrene_as_no-struct.txt", ReactionFileFormat.RXN); |
| 342 |
doubleConversionExampleTest("examples/Styrene_-_Polystyrene_as_no-struct.rxn", "examples/Styrene_-_Polystyrene_as_no-struct.txt", ReactionFileFormat.RD); |
| 343 |
} |
| 344 |
|
| 345 |
@Test |
| 346 |
public void testExample_Tautomerization_01() throws IOException { |
| 347 |
genericExampleTest("examples/Tautomerization_01.rxn", "examples/Tautomerization_01.txt"); |
| 348 |
doubleConversionExampleTest("examples/Tautomerization_01.rxn", "examples/Tautomerization_01.txt", ReactionFileFormat.RXN); |
| 349 |
doubleConversionExampleTest("examples/Tautomerization_01.rxn", "examples/Tautomerization_01.txt", ReactionFileFormat.RD); |
| 350 |
} |
| 351 |
|
| 352 |
@Test |
| 353 |
public void testExample_X__1_product() throws IOException { |
| 354 |
genericExampleTest("examples/X_-_1_product.rxn", "examples/X_-_1_product.txt"); |
| 355 |
doubleConversionExampleTest("examples/X_-_1_product.rxn", "examples/X_-_1_product.txt", ReactionFileFormat.RXN); |
| 356 |
doubleConversionExampleTest("examples/X_-_1_product.rxn", "examples/X_-_1_product.txt", ReactionFileFormat.RD); |
| 357 |
} |
| 358 |
|
| 359 |
@Test |
| 360 |
public void testExample_two_reactants_no_products() throws IOException { |
| 361 |
genericExampleTest("examples/two_reactants_no_products.rxn", "examples/two_reactants_no_products.rxn.rinchi_strings.txt"); |
| 362 |
doubleConversionExampleTest("examples/two_reactants_no_products.rxn", "examples/two_reactants_no_products.rxn.rinchi_strings.txt", ReactionFileFormat.RXN); |
| 363 |
doubleConversionExampleTest("examples/two_reactants_no_products.rxn", "examples/two_reactants_no_products.rxn.rinchi_strings.txt", ReactionFileFormat.RD); |
| 364 |
} |
| 365 |
|
| 366 |
@Test |
| 367 |
public void testExample_R005a() throws IOException { |
| 368 |
genericExampleTest("examples/R005a.rxn", "examples/R005a.rxn.rinchi_strings.txt"); |
| 369 |
doubleConversionExampleTest("examples/R005a.rxn", "examples/R005a.rxn.rinchi_strings.txt", ReactionFileFormat.RXN); |
| 370 |
doubleConversionExampleTest("examples/R005a.rxn", "examples/R005a.rxn.rinchi_strings.txt", ReactionFileFormat.RD); |
| 371 |
} |
| 372 |
|
| 373 |
@Test |
| 374 |
public void testExample_nostruct_two_in_reactants() throws IOException { |
| 375 |
genericExampleTest("examples/nostruct_two_in_reactants.rxn", "examples/nostruct_two_in_reactants.rxn.rinchi_strings.txt"); |
| 376 |
doubleConversionExampleTest("examples/nostruct_two_in_reactants.rxn", "examples/nostruct_two_in_reactants.rxn.rinchi_strings.txt", ReactionFileFormat.RXN); |
| 377 |
doubleConversionExampleTest("examples/nostruct_two_in_reactants.rxn", "examples/nostruct_two_in_reactants.rxn.rinchi_strings.txt", ReactionFileFormat.RD); |
| 378 |
} |
| 379 |
|
| 380 |
@Test |
| 381 |
public void testExample_nostruct_one_in_reactants() throws IOException { |
| 382 |
genericExampleTest("examples/nostruct_one_in_reactants.rxn", "examples/nostruct_one_in_reactants.rxn.rinchi_strings.txt"); |
| 383 |
doubleConversionExampleTest("examples/nostruct_one_in_reactants.rxn", "examples/nostruct_one_in_reactants.rxn.rinchi_strings.txt", ReactionFileFormat.RXN); |
| 384 |
doubleConversionExampleTest("examples/nostruct_one_in_reactants.rxn", "examples/nostruct_one_in_reactants.rxn.rinchi_strings.txt", ReactionFileFormat.RD); |
| 385 |
} |
| 386 |
|
| 387 |
@Test |
| 388 |
public void testExample_nostruct_one_in_products() throws IOException { |
| 389 |
genericExampleTest("examples/nostruct_one_in_products.rxn", "examples/nostruct_one_in_products.rxn.rinchi_strings.txt"); |
| 390 |
doubleConversionExampleTest("examples/nostruct_one_in_products.rxn", "examples/nostruct_one_in_products.rxn.rinchi_strings.txt", ReactionFileFormat.RXN); |
| 391 |
doubleConversionExampleTest("examples/nostruct_one_in_products.rxn", "examples/nostruct_one_in_products.rxn.rinchi_strings.txt", ReactionFileFormat.RD); |
| 392 |
} |
| 393 |
|
| 394 |
@Test |
| 395 |
public void testExample_no_reactants_one_product() throws IOException { |
| 396 |
genericExampleTest("examples/no_reactants_one_product.rxn", "examples/no_reactants_one_product.rxn.rinchi_strings.txt"); |
| 397 |
doubleConversionExampleTest("examples/no_reactants_one_product.rxn", "examples/no_reactants_one_product.rxn.rinchi_strings.txt", ReactionFileFormat.RXN); |
| 398 |
doubleConversionExampleTest("examples/no_reactants_one_product.rxn", "examples/no_reactants_one_product.rxn.rinchi_strings.txt", ReactionFileFormat.RD); |
| 399 |
} |
| 400 |
|
| 401 |
@DisplayName("R005a_with_agents - expected to return an error as agents are not supported by the MDL reader/writer of rinchilib") |
| 402 |
@Test |
| 403 |
public void testFileTextToRinchi_R005a_with_agents() throws IOException { |
| 404 |
// arrange |
| 405 |
final String reactionFilename = "examples/R005a_with_agents.rxn"; |
| 406 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 407 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 408 |
|
| 409 |
// act |
| 410 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 411 |
|
| 412 |
// assert |
| 413 |
assertEquals(1, rinchiOutput.getErrorCode()); |
| 414 |
assertEquals(Status.ERROR, rinchiOutput.getStatus()); |
| 415 |
assertTrue(rinchiOutput.getErrorMessage().endsWith("rinchi::MdlRxnfileReaderError: Reading from 'std::istream', line 5: Invalid component count line - must be 6 characters long.")); |
| 416 |
assertEquals("", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 417 |
|
| 418 |
// a new version of the rinchi software might include the ability to read/write agents from MDL files |
| 419 |
// if so, include the following lines to subject the reaction with agents to a round-trip test |
| 420 |
// genericExampleTest("examples/R005a_with_agents.rxn", "examples/R005a_with_agents.rxn.rinchi_strings.txt"); |
| 421 |
// doubleConversionExampleTest("examples/R005a_with_agents.rxn", "examples/R005a_with_agents.rxn.rinchi_strings.txt", ReactionFileFormat.RXN); |
| 422 |
// doubleConversionExampleTest("examples/R005a_with_agents.rxn", "examples/R005a_with_agents.rxn.rinchi_strings.txt", ReactionFileFormat.RD); |
| 423 |
} |
| 424 |
|
| 425 |
@DisplayName("testFileTextToRinchi_example_01_CCR") |
| 426 |
@Test |
| 427 |
public void testFileTextToRinchi_example_01_CCR() throws IOException { |
| 428 |
// arrange |
| 429 |
final String reactionFilename = "examples/Example_01_CCR.rdf"; |
| 430 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 431 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 432 |
|
| 433 |
// act |
| 434 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 435 |
|
| 436 |
// assert |
| 437 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 438 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 439 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 440 |
assertEquals("RInChI=1.00.1S/C18H13NO5S2/c1-12-2-4-14(5-3-12)26(21,22)19-13-6-9-18(10-7-13)23-15-8-11-25-16(15)" + |
| 441 |
"17(20)24-18/h2-11H,1H3/b19-13-<>C18H15NO5S2/c1-12-2-8-15(9-3-12)26(22,23)19-13-4-6-14(7-5-13)24-16-10-11-25-17(16)" + |
| 442 |
"18(20)21/h2-11,19H,1H3,(H,20,21)<>C2H3N/c1-2-3/h1H3!C8H20N.ClHO4/c1-5-9(6-2,7-3)8-4;2-1(3,4)5/h5-8H2,1-4H3;(H,2,3,4,5)/" + |
| 443 |
"q+1;/p-1/d-", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 444 |
} |
| 445 |
|
| 446 |
@DisplayName("testFileTextToRinchiKey_example_01_CCR") |
| 447 |
@Test |
| 448 |
public void testFileTextToRinchiKey_example_01_CCR() throws IOException { |
| 449 |
// arrange |
| 450 |
final String reactionFilename = "examples/Example_01_CCR.rdf"; |
| 451 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 452 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 453 |
|
| 454 |
// Long-RInChIKey |
| 455 |
// act |
| 456 |
RinchiKeyOutput longRinchiKeyOut = JnaRinchi.fileTextToRinchiKey(reactionText, RinchiKeyType.LONG); |
| 457 |
// assert |
| 458 |
assertEquals(0, longRinchiKeyOut.getErrorCode()); |
| 459 |
assertEquals(Status.SUCCESS, longRinchiKeyOut.getStatus()); |
| 460 |
assertEquals("", longRinchiKeyOut.getErrorMessage()); |
| 461 |
assertEquals("Long-RInChIKey=SA-BUHFF-OCEYRUMTOAEWEA-UYRXBGFRSA-N--HRQNWWCYHJTAPI-UHFFFAOYSA-N--WEVYAHXRMPXWCK-UHFFFAOYSA-N-WGHUNMFFLAMBJD-UHFFFAOYSA-M", |
| 462 |
longRinchiKeyOut.getRinchiKey(), "Long-RinchiKey for " + reactionFilename); |
| 463 |
|
| 464 |
// Short-RInChIKey |
| 465 |
// act |
| 466 |
RinchiKeyOutput shortRinchiKeyOut = JnaRinchi.fileTextToRinchiKey(reactionText, RinchiKeyType.SHORT); |
| 467 |
// assert |
| 468 |
assertEquals(0, shortRinchiKeyOut.getErrorCode()); |
| 469 |
assertEquals(Status.SUCCESS, shortRinchiKeyOut.getStatus()); |
| 470 |
assertEquals("", shortRinchiKeyOut.getErrorMessage()); |
| 471 |
assertEquals("Short-RInChIKey=SA-BUHFF-OCEYRUMTOA-HRQNWWCYHJ-ANFMRDWEKN-NDGAC-NUHFF-MUHFF-ZZZ", |
| 472 |
shortRinchiKeyOut.getRinchiKey(), "Short-RinchiKey for " + reactionFilename); |
| 473 |
|
| 474 |
// Web-RInChIKey |
| 475 |
// act |
| 476 |
RinchiKeyOutput webRinchiKeyOut = JnaRinchi.fileTextToRinchiKey(reactionText, RinchiKeyType.WEB); |
| 477 |
// assert |
| 478 |
assertEquals(0, webRinchiKeyOut.getErrorCode()); |
| 479 |
assertEquals(Status.SUCCESS, webRinchiKeyOut.getStatus()); |
| 480 |
assertEquals("", webRinchiKeyOut.getErrorMessage()); |
| 481 |
assertEquals("Web-RInChIKey=YVHOQDQUXJQWHSZQW-MSWCGYDXJTZWXSA", webRinchiKeyOut.getRinchiKey(), "Web-RinchiKey for " + reactionFilename); |
| 482 |
} |
| 483 |
|
| 484 |
@DisplayName("testDecomposeRinchi_with_AuxInfo") |
| 485 |
@Test |
| 486 |
public void testDecomposeRinchi_with_AuxInfo() { |
| 487 |
// arrange |
| 488 |
final String rinchi = "RInChI=1.00.1S/C18H13NO5S2/c1-12-2-4-14(5-3-12)26(21,22)19-13-6-9-18(10-7-13)23-15-8-11-25-16(15)17(20)24-18/h2-11H," + |
| 489 |
"1H3/b19-13-<>C18H15NO5S2/c1-12-2-8-15(9-3-12)26(22,23)19-13-4-6-14(7-5-13)24-16-10-11-25-17(16)18(20)21/h2-11,19H,1H3,(H,20,21)" + |
| 490 |
"<>C2H3N/c1-2-3/h1H3!C8H20N.ClHO4/c1-5-9(6-2,7-3)8-4;2-1(3,4)5/h5-8H2,1-4H3;(H,2,3,4,5)/q+1;/p-1/d-"; |
| 491 |
final String auxInfo = "RAuxInfo=1.00.1/0/N:26,23,24,21,22,8,9,11,4,5,15,25,13,18,6,10,7,1,16,12,19,20,2,3,14,17/E:(2,3)(4,5)(6,7)(9,10)(21,22)" + |
| 492 |
"/CRV:26.6/rA:26nCOOCCCCCCCCOCSCNSCOOCCCCCC/rB:s1;s1;s1;s1;s2;s3;d4;d5;d6s7;s6;d7;s8s9;s10;d11s14;d13;s16;s17;d17;d17;s18;d18;d21;s22;" + |
| 493 |
"s23d24;s25;/rC:2.9831,-1.7951,0;1.65,-1.0285,0;2.9831,-3.3081,0;2.9831,-.2553,0;4.3162,-2.5416,0;.3265,-1.7951,0;1.65,-4.0813,0;4.3162," + |
| 494 |
".5112,0;5.6426,-1.7951,0;.3265,-3.3081,0;-1.1738,-1.3285,0;1.65,-5.6211,0;5.6426,-.2553,0;-1.1304,-3.7747,0;-2.0639,-2.5216,0;6.9691," + |
| 495 |
".5112,0;8.3022,-.2553,0;9.6353,-1.0285,0;9.0754,1.1378,0;7.5357,-1.5351,0;9.6353,-2.5483,0;10.9684,-.2553,0;10.9684,-3.3215,0;12.3082," + |
| 496 |
"-1.0285,0;12.3082,-2.5483,0;13.6413,-3.3215,0;<>1/N:26,23,24,13,14,11,12,21,22,4,8,25,15,7,18,1,2,6,16,9,10,19,20,3,5,17" + |
| 497 |
"/E:(2,3)(4,5)(6,7)(8,9)(20,21)(22,23)/CRV:26.6/rA:26nCCOCSCCCOOCCCCCNSCOOCCCCCC/rB:d1;s1;s1;s2;s2;s3;d4s5;s6;d6;s7;d7;d11;s12;s13d14;" + |
| 498 |
"s15;s16;s17;d17;d17;s18;d18;d21;s22;s23d24;s25;/rC:-10.0504,-6.767,0;-9.6286,-8.2146,0;-9.1595,-5.5177,0;-11.6085,-6.767,0;-10.8357," + |
| 499 |
"-9.0711,0;-8.1587,-8.7063,0;-10.0326,-4.2448,0;-12.0823,-8.1749,0;-7.8513,-10.1616,0;-6.9429,-7.6753,0;-9.3653,-2.8527,0;-11.5645," + |
| 500 |
"-4.3558,0;-10.2081,-1.5918,0;-12.4292,-3.0869,0;-11.7574,-1.7028,0;-12.6309,-.4297,0;-11.7138,.8195,0;-10.7833,2.0559,0;-13.0173," + |
| 501 |
"1.7436,0;-10.5154,-.0808,0;-9.2776,1.889,0;-11.4238,3.4821,0;-8.3605,3.1398,0;-10.4892,4.7258,0;-8.9752,4.5552,0;-8.0705,5.7965,0;" + |
| 502 |
"<>0/N:2,1,3/rA:3nCCN/rB:s1;t1;/rC:.5157,.2238,0;-1.0243,.2238,0;2.088,.2238,0;!1/N:6,7,8,9,2,3,4,5,1;10,11,12,13,14/E:(1,2,3,4)" + |
| 503 |
"(5,6,7,8);(2,3,4,5)/CRV:9+1;1.7/rA:14nN+CCCCCCCCClOOOO-/rB:s1;s1;s1;s1;s2;s3;s4;s5;;d10;d10;d10;s10;/rC:-2.3374,.2568,0;-3.8783," + |
| 504 |
".2568,0;-1.8238,1.7084,0;-1.0384,-.5695,0;-3.0446,-1.1091,0;-4.3956,-1.1948,0;-3.0222,2.6761,0;.1749,.3759,0;-1.9913,-2.2332,0;3.0595," + |
| 505 |
".2308,0;3.4763,1.7419,0;3.4949,-1.299,0;4.5222,.2159,0;1.5186,.2308,0;"; |
| 506 |
|
| 507 |
List<String> inchis = new ArrayList<>(); |
| 508 |
inchis.add("InChI=1S/C18H15NO5S2/c1-12-2-8-15(9-3-12)26(22,23)19-13-4-6-14(7-5-13)24-16-10-11-25-17(16)18(20)21/h2-11,19H,1H3,(H,20,21)"); |
| 509 |
inchis.add("InChI=1S/C18H13NO5S2/c1-12-2-4-14(5-3-12)26(21,22)19-13-6-9-18(10-7-13)23-15-8-11-25-16(15)17(20)24-18/h2-11H,1H3/b19-13-"); |
| 510 |
inchis.add("InChI=1S/C2H3N/c1-2-3/h1H3"); |
| 511 |
inchis.add("InChI=1S/C8H20N.ClHO4/c1-5-9(6-2,7-3)8-4;2-1(3,4)5/h5-8H2,1-4H3;(H,2,3,4,5)/q+1;/p-1"); |
| 512 |
assertEquals(4, inchis.size()); |
| 513 |
|
| 514 |
List<String> auxInfos = new ArrayList<>(); |
| 515 |
auxInfos.add("AuxInfo=1/1/N:26,23,24,13,14,11,12,21,22,4,8,25,15,7,18,1,2,6,16,9,10,19,20,3,5,17/E:(2,3)(4,5)(6,7)(8,9)(20,21)(22,23)" + |
| 516 |
"/CRV:26.6/rA:26nCCOCSCCCOOCCCCCNSCOOCCCCCC/rB:d1;s1;s1;s2;s2;s3;d4s5;s6;d6;s7;d7;d11;s12;s13d14;s15;s16;s17;d17;d17;" + |
| 517 |
"s18;d18;d21;s22;s23d24;s25;/rC:-10.0504,-6.767,0;-9.6286,-8.2146,0;-9.1595,-5.5177,0;-11.6085,-6.767,0;-10.8357," + |
| 518 |
"-9.0711,0;-8.1587,-8.7063,0;-10.0326,-4.2448,0;-12.0823,-8.1749,0;-7.8513,-10.1616,0;-6.9429,-7.6753,0;-9.3653,-2.8527,0;" + |
| 519 |
"-11.5645,-4.3558,0;-10.2081,-1.5918,0;-12.4292,-3.0869,0;-11.7574,-1.7028,0;-12.6309,-.4297,0;-11.7138,.8195,0;-10.7833,2.0559,0;" + |
| 520 |
"-13.0173,1.7436,0;-10.5154,-.0808,0;-9.2776,1.889,0;-11.4238,3.4821,0;-8.3605,3.1398,0;-10.4892,4.7258,0;-8.9752,4.5552,0;-8.0705,5.7965,0;"); |
| 521 |
auxInfos.add("AuxInfo=1/0/N:26,23,24,21,22,8,9,11,4,5,15,25,13,18,6,10,7,1,16,12,19,20,2,3,14,17/E:(2,3)(4,5)(6,7)(9,10)(21,22)" + |
| 522 |
"/CRV:26.6/rA:26nCOOCCCCCCCCOCSCNSCOOCCCCCC/rB:s1;s1;s1;s1;s2;s3;d4;d5;d6s7;s6;d7;s8s9;s10;d11s14;d13;s16;s17;d17;" + |
| 523 |
"d17;s18;d18;d21;s22;s23d24;s25;/rC:2.9831,-1.7951,0;1.65,-1.0285,0;2.9831,-3.3081,0;2.9831,-.2553,0;4.3162,-2.5416,0;" + |
| 524 |
".3265,-1.7951,0;1.65,-4.0813,0;4.3162,.5112,0;5.6426,-1.7951,0;.3265,-3.3081,0;-1.1738,-1.3285,0;1.65,-5.6211,0;" + |
| 525 |
"5.6426,-.2553,0;-1.1304,-3.7747,0;-2.0639,-2.5216,0;6.9691,.5112,0;8.3022,-.2553,0;9.6353,-1.0285,0;9.0754,1.1378,0;" + |
| 526 |
"7.5357,-1.5351,0;9.6353,-2.5483,0;10.9684,-.2553,0;10.9684,-3.3215,0;12.3082,-1.0285,0;12.3082,-2.5483,0;13.6413,-3.3215,0;"); |
| 527 |
auxInfos.add("AuxInfo=1/0/N:2,1,3/rA:3nCCN/rB:s1;t1;/rC:.5157,.2238,0;-1.0243,.2238,0;2.088,.2238,0;"); |
| 528 |
auxInfos.add("AuxInfo=1/1/N:6,7,8,9,2,3,4,5,1;10,11,12,13,14/E:(1,2,3,4)(5,6,7,8);(2,3,4,5)/CRV:9+1;1.7/rA:14nN+CCCCCCCCClOOOO-" + |
| 529 |
"/rB:s1;s1;s1;s1;s2;s3;s4;s5;;d10;d10;d10;s10;/rC:-2.3374,.2568,0;-3.8783,.2568,0;-1.8238,1.7084,0;-1.0384,-.5695,0;" + |
| 530 |
"-3.0446,-1.1091,0;-4.3956,-1.1948,0;-3.0222,2.6761,0;.1749,.3759,0;-1.9913,-2.2332,0;3.0595,.2308,0;3.4763,1.7419,0;" + |
| 531 |
"3.4949,-1.299,0;4.5222,.2159,0;1.5186,.2308,0;"); |
| 532 |
assertEquals(4, auxInfos.size()); |
| 533 |
|
| 534 |
List<ReactionComponentRole> componentRoles = new ArrayList<>(); |
| 535 |
componentRoles.add(ReactionComponentRole.REAGENT); |
| 536 |
componentRoles.add(ReactionComponentRole.PRODUCT); |
| 537 |
componentRoles.add(ReactionComponentRole.AGENT); |
| 538 |
componentRoles.add(ReactionComponentRole.AGENT); |
| 539 |
assertEquals(4, componentRoles.size()); |
| 540 |
|
| 541 |
// act |
| 542 |
RinchiDecompositionOutput rinchiDecompositionOutput = JnaRinchi.decomposeRinchi(rinchi, auxInfo); |
| 543 |
|
| 544 |
// assert |
| 545 |
assertEquals(0, rinchiDecompositionOutput.getErrorCode()); |
| 546 |
assertEquals(Status.SUCCESS, rinchiDecompositionOutput.getStatus()); |
| 547 |
assertEquals("", rinchiDecompositionOutput.getErrorMessage()); |
| 548 |
assertEquals("-", rinchiDecompositionOutput.getDirection().getShortRinchiDesignation(), "Direction for RInChI decomposition"); |
| 549 |
assertEquals(inchis.size(), rinchiDecompositionOutput.getNumberOfComponents(), "number of components from RInChI decomposition"); |
| 550 |
|
| 551 |
// assert expected and actual auxinfo and reaction component role |
| 552 |
for (int i = 0; i < rinchiDecompositionOutput.getNumberOfComponents(); i++) { |
| 553 |
assertEquals(inchis.get(i), rinchiDecompositionOutput.getInchis()[i], "asserting inchi equality for array position " + i); |
| 554 |
assertEquals(auxInfos.get(i), rinchiDecompositionOutput.getAuxInfos()[i], "asserting auxinfo equality for array position " + i); |
| 555 |
assertEquals(componentRoles.get(i), rinchiDecompositionOutput.getRoles()[i], "asserting reaction component role equality for array position " + i); |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
@DisplayName("testDecomposeRinchi_without_AuxInfo") |
| 560 |
@Test |
| 561 |
public void testDecomposeRinchi_without_AuxInfo() { |
| 562 |
// arrange |
| 563 |
final String rinchi = "RInChI=1.00.1S/C18H13NO5S2/c1-12-2-4-14(5-3-12)26(21,22)19-13-6-9-18(10-7-13)23-15-8-11-25-16(15)17(20)24-18/h2-11H," + |
| 564 |
"1H3/b19-13-<>C18H15NO5S2/c1-12-2-8-15(9-3-12)26(22,23)19-13-4-6-14(7-5-13)24-16-10-11-25-17(16)18(20)21/h2-11,19H,1H3,(H,20,21)" + |
| 565 |
"<>C2H3N/c1-2-3/h1H3!C8H20N.ClHO4/c1-5-9(6-2,7-3)8-4;2-1(3,4)5/h5-8H2,1-4H3;(H,2,3,4,5)/q+1;/p-1/d-"; |
| 566 |
final String auxInfo = ""; |
| 567 |
|
| 568 |
List<String> inchis = new ArrayList<>(); |
| 569 |
inchis.add("InChI=1S/C18H15NO5S2/c1-12-2-8-15(9-3-12)26(22,23)19-13-4-6-14(7-5-13)24-16-10-11-25-17(16)18(20)21/h2-11,19H,1H3,(H,20,21)"); |
| 570 |
inchis.add("InChI=1S/C18H13NO5S2/c1-12-2-4-14(5-3-12)26(21,22)19-13-6-9-18(10-7-13)23-15-8-11-25-16(15)17(20)24-18/h2-11H,1H3/b19-13-"); |
| 571 |
inchis.add("InChI=1S/C2H3N/c1-2-3/h1H3"); |
| 572 |
inchis.add("InChI=1S/C8H20N.ClHO4/c1-5-9(6-2,7-3)8-4;2-1(3,4)5/h5-8H2,1-4H3;(H,2,3,4,5)/q+1;/p-1"); |
| 573 |
assertEquals(4, inchis.size()); |
| 574 |
|
| 575 |
List<String> auxInfos = new ArrayList<>(); |
| 576 |
auxInfos.add(""); |
| 577 |
auxInfos.add(""); |
| 578 |
auxInfos.add(""); |
| 579 |
auxInfos.add(""); |
| 580 |
assertEquals(4, auxInfos.size()); |
| 581 |
|
| 582 |
List<ReactionComponentRole> componentRoles = new ArrayList<>(); |
| 583 |
componentRoles.add(ReactionComponentRole.REAGENT); |
| 584 |
componentRoles.add(ReactionComponentRole.PRODUCT); |
| 585 |
componentRoles.add(ReactionComponentRole.AGENT); |
| 586 |
componentRoles.add(ReactionComponentRole.AGENT); |
| 587 |
assertEquals(4, componentRoles.size()); |
| 588 |
|
| 589 |
// act |
| 590 |
RinchiDecompositionOutput rinchiDecompositionOutput = JnaRinchi.decomposeRinchi(rinchi, auxInfo); |
| 591 |
|
| 592 |
// assert |
| 593 |
assertEquals(0, rinchiDecompositionOutput.getErrorCode()); |
| 594 |
assertEquals(Status.SUCCESS, rinchiDecompositionOutput.getStatus()); |
| 595 |
assertEquals("", rinchiDecompositionOutput.getErrorMessage()); |
| 596 |
assertEquals("-", rinchiDecompositionOutput.getDirection().getShortRinchiDesignation(), "Direction for RInChI decomposition"); |
| 597 |
assertEquals(inchis.size(), rinchiDecompositionOutput.getNumberOfComponents(), "number of components from RInChI decomposition"); |
| 598 |
|
| 599 |
// assert expected and actual auxinfo and reaction component role |
| 600 |
for (int i = 0; i < rinchiDecompositionOutput.getNumberOfComponents(); i++) { |
| 601 |
assertEquals(inchis.get(i), rinchiDecompositionOutput.getInchis()[i], "asserting inchi equality for array position " + i); |
| 602 |
assertEquals(auxInfos.get(i), rinchiDecompositionOutput.getAuxInfos()[i], "asserting auxinfo equality for array position " + i); |
| 603 |
assertEquals(componentRoles.get(i), rinchiDecompositionOutput.getRoles()[i], "asserting reaction component role equality for array position " + i); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
@DisplayName("testDecomposeRinchi_without_AuxInfo") |
| 608 |
@Test |
| 609 |
public void testDecomposeRinchi_NoStructures() { |
| 610 |
// arrange |
| 611 |
final String rinchi = "RInChI=1.00.1S/C4H9BrO/c1-3(5)4(2)6/h3-4,6H,1-2H3/t3-,4+/m1/s1!Na.H2O/h;1H2/q+1;/p-1/d+/u1-2-3"; |
| 612 |
final String auxInfo = ""; |
| 613 |
|
| 614 |
List<String> inchis = new ArrayList<>(); |
| 615 |
inchis.add("InChI=1S/C4H9BrO/c1-3(5)4(2)6/h3-4,6H,1-2H3/t3-,4+/m1/s1"); |
| 616 |
inchis.add("InChI=1S/Na.H2O/h;1H2/q+1;/p-1"); |
| 617 |
inchis.add("InChI=1S//"); |
| 618 |
inchis.add("InChI=1S//"); |
| 619 |
inchis.add("InChI=1S//"); |
| 620 |
inchis.add("InChI=1S//"); |
| 621 |
inchis.add("InChI=1S//"); |
| 622 |
inchis.add("InChI=1S//"); |
| 623 |
assertEquals(8, inchis.size()); |
| 624 |
|
| 625 |
List<String> auxInfos = new ArrayList<>(); |
| 626 |
auxInfos.add(""); |
| 627 |
auxInfos.add(""); |
| 628 |
auxInfos.add(""); |
| 629 |
auxInfos.add(""); |
| 630 |
auxInfos.add(""); |
| 631 |
auxInfos.add(""); |
| 632 |
auxInfos.add(""); |
| 633 |
auxInfos.add(""); |
| 634 |
assertEquals(8, auxInfos.size()); |
| 635 |
|
| 636 |
List<ReactionComponentRole> componentRoles = new ArrayList<>(); |
| 637 |
componentRoles.add(ReactionComponentRole.REAGENT); |
| 638 |
componentRoles.add(ReactionComponentRole.REAGENT); |
| 639 |
componentRoles.add(ReactionComponentRole.REAGENT); |
| 640 |
componentRoles.add(ReactionComponentRole.PRODUCT); |
| 641 |
componentRoles.add(ReactionComponentRole.PRODUCT); |
| 642 |
componentRoles.add(ReactionComponentRole.AGENT); |
| 643 |
componentRoles.add(ReactionComponentRole.AGENT); |
| 644 |
componentRoles.add(ReactionComponentRole.AGENT); |
| 645 |
assertEquals(8, componentRoles.size()); |
| 646 |
|
| 647 |
// act |
| 648 |
RinchiDecompositionOutput rinchiDecompositionOutput = JnaRinchi.decomposeRinchi(rinchi, auxInfo); |
| 649 |
|
| 650 |
// assert |
| 651 |
assertEquals(0, rinchiDecompositionOutput.getErrorCode()); |
| 652 |
assertEquals(Status.SUCCESS, rinchiDecompositionOutput.getStatus()); |
| 653 |
assertEquals("", rinchiDecompositionOutput.getErrorMessage()); |
| 654 |
assertEquals("+", rinchiDecompositionOutput.getDirection().getShortRinchiDesignation(), "Direction for RInChI decomposition"); |
| 655 |
assertEquals(inchis.size(), rinchiDecompositionOutput.getNumberOfComponents(), "number of components from RInChI decomposition"); |
| 656 |
|
| 657 |
// assert expected and actual auxinfo and reaction component role |
| 658 |
for (int i = 0; i < rinchiDecompositionOutput.getNumberOfComponents(); i++) { |
| 659 |
assertEquals(inchis.get(i), rinchiDecompositionOutput.getInchis()[i], "asserting inchi equality for array position " + i); |
| 660 |
assertEquals(auxInfos.get(i), rinchiDecompositionOutput.getAuxInfos()[i], "asserting auxinfo equality for array position " + i); |
| 661 |
assertEquals(componentRoles.get(i), rinchiDecompositionOutput.getRoles()[i], "asserting reaction component role equality for array position " + i); |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
@DisplayName("testFileTextToRinchi_example_03_metab_UDM") |
| 666 |
@Test |
| 667 |
public void testFileTextToRinchi_example_03_metab_UDM() throws IOException { |
| 668 |
// arrange |
| 669 |
final String reactionFilename = "examples/Example_03_metab_UDM.rdf"; |
| 670 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 671 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 672 |
|
| 673 |
// act |
| 674 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 675 |
|
| 676 |
// assert |
| 677 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 678 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 679 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 680 |
assertEquals("RInChI=1.00.1S/C7H13BrN2O2/c1-3-7(8,4-2)5(11)10-6(9)12/h3-4H2,1-2H3,(H3,9,10,11,12)<>" + |
| 681 |
"C7H14N2O2/c1-3-5(4-2)6(10)9-7(8)11/h5H,3-4H2,1-2H3,(H3,8,9,10,11)<>2H3O4P/c2*1-5(2,3)4/h2*(H3,1,2,3,4)" + |
| 682 |
"/p-3!C9H15BrN2O3/c1-4-9(10,5-2)7(14)12-8(15)11-6(3)13/h4-5H2,1-3H3,(H2,11,12,13,14,15)!H2O/h1H2!Na.H/d+", |
| 683 |
rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 684 |
} |
| 685 |
|
| 686 |
@DisplayName("testFileTextToRinchi_example_04_simple") |
| 687 |
@Test |
| 688 |
public void testFileTextToRinchi_example_04_simple() throws IOException { |
| 689 |
// arrange |
| 690 |
final String reactionFilename = "examples/Example_04_simple.rdf"; |
| 691 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 692 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 693 |
|
| 694 |
// act |
| 695 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 696 |
|
| 697 |
// assert |
| 698 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 699 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 700 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 701 |
assertEquals("RInChI=1.00.1S/C24H34O2Si/c1-6-21(18-25)17-20(2)19-26-27(24(3,4)5,22-13-9-7-10-14-22)23-15-11-8-12-16-23" + |
| 702 |
"/h7-16,18,20-21H,6,17,19H2,1-5H3/t20-,21-/m1/s1<>C24H36O2Si/c1-6-21(18-25)17-20(2)19-26-27(24(3,4)5,22-13-9-7-10-14-22)" + |
| 703 |
"23-15-11-8-12-16-23/h7-16,20-21,25H,6,17-19H2,1-5H3/t20-,21-/m1/s1/d-", |
| 704 |
rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 705 |
} |
| 706 |
|
| 707 |
@DisplayName("testFileTextToRinchi_example_04_simple") |
| 708 |
@Test |
| 709 |
public void testFileTextToRinchi_example_05_groups_UDM() throws IOException { |
| 710 |
// arrange |
| 711 |
final String reactionFilename = "examples/Example_05_groups_UDM.rdf"; |
| 712 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 713 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 714 |
|
| 715 |
// act |
| 716 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 717 |
|
| 718 |
// assert |
| 719 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 720 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 721 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 722 |
assertEquals("RInChI=1.00.1S/C28H48O4Si/c1-19(2)33(20(3)4,21(5)6)32-28(24(9)27(30)25(10)29)23(8)16-22(7)17-31-18-26-14-12-11-13-15-26" + |
| 723 |
"/h11-16,19-22,24-25,28-29H,17-18H2,1-10H3/b23-16+/t22-,24+,25+,28+/m1/s1<>C34H62O4Si2" + |
| 724 |
"/c1-24(2)40(25(3)4,26(5)6)38-33(29(9)32(35)30(10)37-39(14,15)34(11,12)13)28(8)21-27(7)22-36-23-31-19-17-16-18-20-31" + |
| 725 |
"/h16-21,24-27,29-30,33H,22-23H2,1-15H3/b28-21+/t27-,29+,30+,33+/m1/s1<>C10H16O4S/c1-9(2)7-3-4-10(9,8(11)5-7)6-15(12,13)14" + |
| 726 |
"/h7H,3-6H2,1-2H3,(H,12,13,14)!CH2Cl2/c2-1-3/h1H2!CH4O/c1-2/h2H,1H3!CH4O/c1-2/h2H,1H3/d-", |
| 727 |
rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 728 |
} |
| 729 |
|
| 730 |
@DisplayName("testFileTextToRinchi_5_variations_1_step_each") |
| 731 |
@Test |
| 732 |
public void testFileTextToRinchi_5_variations_1_step_each() throws IOException { |
| 733 |
// arrange |
| 734 |
final String reactionFilename = "examples/5_variations_1_step_each.rdf"; |
| 735 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 736 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 737 |
|
| 738 |
// act |
| 739 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 740 |
|
| 741 |
// assert |
| 742 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 743 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 744 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 745 |
assertEquals("RInChI=1.00.1S/C6H10O/c7-6-4-2-1-3-5-6/h1-5H2<>C6H12O/c7-6-4-2-1-3-5-6/h6-7H,1-5H2<>3C18H15P.2ClH.Ru" + |
| 746 |
"/c3*1-4-10-16(11-5-1)19(17-12-6-2-7-13-17)18-14-8-3-9-15-18;;;/h3*1-15H;2*1H;/q;;;;;+2/p-2!C3H8O" + |
| 747 |
"/c1-3(2)4/h3-4H,1-2H3!Na.H2O/h;1H2/q+1;/p-1/d+", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 748 |
} |
| 749 |
|
| 750 |
@DisplayName("testFileTextToRinchi_1_variation_4_steps") |
| 751 |
@Test |
| 752 |
public void testFileTextToRinchi_1_variation_4_steps() throws IOException { |
| 753 |
// arrange |
| 754 |
final String reactionFilename = "examples/1_variation_4_steps.rdf"; |
| 755 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 756 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 757 |
|
| 758 |
// act |
| 759 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 760 |
|
| 761 |
// assert |
| 762 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 763 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 764 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 765 |
assertEquals("RInChI=1.00.1S/C12H17NOS/c1-3-13(4-2)12(14)15-10-11-8-6-5-7-9-11/h5-9H,3-4,10H2,1-2H3<>C4H11N/c1-3-5-4-2" + |
| 766 |
"/h5H,3-4H2,1-2H3!C7H7Br/c8-6-7-4-2-1-3-5-7/h1-5H,6H2!CO/c1-2!S8/c1-2-4-6-8-7-5-3-1<>2ClH.2H2N.Pt/h2*1H;2*1H2;/q;;2*-1;+4" + |
| 767 |
"/p-2!2ClH.Pd/h2*1H;/q;;+2/p-2!3C2H4O2.Fe/c3*1-2(3)4;/h3*1H3,(H,3,4);/q;;;+3/p-3!C4H10O/c1-3-5-4-2/h3-4H2,1-2H3!C4H8O" + |
| 768 |
"/c1-2-4-5-3-1/h1-4H2!C4H8O/c1-2-4-5-3-1/h1-4H2!C4H8O/c1-2-4-5-3-1/h1-4H2!C4H9.Li/c1-3-4-2;/h1,3-4H2,2H3;!C6H12" + |
| 769 |
"/c1-2-4-6-5-3-1/h1-6H2!C6H14/c1-3-5-6-4-2/h3-6H2,1-2H3!C6H6/c1-2-4-6-5-3-1/h1-6H/d-", rinchiOutput.getRinchi(), |
| 770 |
"Rinchi for " + reactionFilename); |
| 771 |
} |
| 772 |
|
| 773 |
@Test |
| 774 |
public void testFileTextToRinchi_ok__nostruct_A() throws IOException { |
| 775 |
// arrange |
| 776 |
final String reactionFilename = "examples/ok__nostruct-A.rxn"; |
| 777 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 778 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 779 |
|
| 780 |
// act |
| 781 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 782 |
|
| 783 |
// assert |
| 784 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 785 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 786 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 787 |
assertEquals("RInChI=1.00.1S//d+/u1-1-0", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 788 |
} |
| 789 |
|
| 790 |
@Test |
| 791 |
public void testFileTextToRinchi_ok__nostruct_X() throws IOException { |
| 792 |
// arrange |
| 793 |
final String reactionFilename = "examples/ok__nostruct-X.rdf"; |
| 794 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 795 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 796 |
|
| 797 |
// act |
| 798 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 799 |
|
| 800 |
// assert |
| 801 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 802 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 803 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 804 |
assertEquals("RInChI=1.00.1S/<><>C4H8O/c1-2-4-5-3-1/h1-4H2!Mn.2O/d+/u1-1-0", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 805 |
} |
| 806 |
|
| 807 |
@Test |
| 808 |
public void testFileTextToRinchi_ok__R_A() throws IOException { |
| 809 |
// arrange |
| 810 |
final String reactionFilename = "examples/ok__R-A.rxn"; |
| 811 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 812 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 813 |
|
| 814 |
// act |
| 815 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 816 |
|
| 817 |
// assert |
| 818 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 819 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 820 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 821 |
assertEquals("RInChI=1.00.1S//d+/u1-1-0", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 822 |
} |
| 823 |
|
| 824 |
@Test |
| 825 |
public void testFileTextToRinchi_ok__R_X() throws IOException { |
| 826 |
// arrange |
| 827 |
final String reactionFilename = "examples/ok__R-X.rdf"; |
| 828 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 829 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 830 |
|
| 831 |
// act |
| 832 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 833 |
|
| 834 |
// assert |
| 835 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 836 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 837 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 838 |
assertEquals("RInChI=1.00.1S/<><>C2H6O/c1-2-3/h3H,2H2,1H3!Cu/d+/u1-1-0", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 839 |
} |
| 840 |
|
| 841 |
@Test |
| 842 |
public void testFileTextToRinchi_ok__star_star_nostruct() throws IOException { |
| 843 |
// arrange |
| 844 |
final String reactionFilename = "examples/ok__star_star-nostruct.rdf"; |
| 845 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 846 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 847 |
|
| 848 |
// act |
| 849 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 850 |
|
| 851 |
// assert |
| 852 |
assertEquals(0, rinchiOutput.getErrorCode()); |
| 853 |
assertEquals(Status.SUCCESS, rinchiOutput.getStatus()); |
| 854 |
assertEquals("", rinchiOutput.getErrorMessage()); |
| 855 |
assertEquals("RInChI=1.00.1S/<><>Cu.O/d+/u2-1-0", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 856 |
} |
| 857 |
|
| 858 |
@DisplayName("testFileTextToRinchi_err__R_reactant_A_product - expected to return an error status and error message") |
| 859 |
@Test |
| 860 |
public void testExample_err__R_reactant_A_product() throws IOException { |
| 861 |
// arrange |
| 862 |
final String reactionFilename = "examples/err__R_reactant-A_product.rxn"; |
| 863 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 864 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 865 |
|
| 866 |
// act |
| 867 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 868 |
|
| 869 |
// assert |
| 870 |
assertEquals(1, rinchiOutput.getErrorCode()); |
| 871 |
assertEquals(Status.ERROR, rinchiOutput.getStatus()); |
| 872 |
assertTrue(rinchiOutput.getErrorMessage().endsWith("rinchi::InChIGeneratorError: Error: no InChI has been created.")); |
| 873 |
assertEquals("", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 874 |
} |
| 875 |
|
| 876 |
@DisplayName("testFileTextToRinchi_err__R_reactant_A_product - expected to return an error status and error message") |
| 877 |
@Test |
| 878 |
public void testExample_err__star_reactant_product() throws IOException { |
| 879 |
// arrange |
| 880 |
final String reactionFilename = "examples/err__star_reactant-product.rdf"; |
| 881 |
String reactionText = TestUtils.readTextFromResourceAsString(reactionFilename); |
| 882 |
assertNotNull(reactionText, "Reading reaction from text file " + reactionFilename); |
| 883 |
|
| 884 |
// act |
| 885 |
RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionText); |
| 886 |
|
| 887 |
// assert |
| 888 |
assertEquals(1, rinchiOutput.getErrorCode()); |
| 889 |
assertEquals(Status.ERROR, rinchiOutput.getStatus()); |
| 890 |
// error messages from rinchi lib differ slightly depending on the platform win/linux |
| 891 |
// win: contains 'class' before any classes; linux: does not contain 'class' before any classes |
| 892 |
// complete message reads: |
| 893 |
// [class] rinchi::MdlRDfileReaderError: Reading from 'std::istream', line 87, [class] rinchi::InChIGeneratorError: Error: no InChI has been created. |
| 894 |
// we assert the parts of the error message string before and after 'class' |
| 895 |
assertTrue(rinchiOutput.getErrorMessage().contains("rinchi::MdlRDfileReaderError: Reading from 'std::istream', line 87,")); |
| 896 |
assertTrue(rinchiOutput.getErrorMessage().endsWith("rinchi::InChIGeneratorError: Error: no InChI has been created.")); |
| 897 |
assertEquals("", rinchiOutput.getRinchi(), "Rinchi for " + reactionFilename); |
| 898 |
} |
| 899 |
|
| 900 |
@Test |
| 901 |
public void testDecomposeRinchi_rinchiIsNull() { |
| 902 |
// act & assert |
| 903 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.decomposeRinchi(null, "")); |
| 904 |
Assertions.assertEquals("The argument 'rinchi' must not be null.", exception.getMessage()); |
| 905 |
} |
| 906 |
|
| 907 |
@Test |
| 908 |
public void testDecomposeRinchi_auxInfoIsNull() { |
| 909 |
// act & assert |
| 910 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.decomposeRinchi("", null)); |
| 911 |
Assertions.assertEquals("The argument 'auxInfo' must not be null.", exception.getMessage()); |
| 912 |
} |
| 913 |
|
| 914 |
@Test |
| 915 |
public void testRinchiToRinchiKey_keyTypeIsNull() { |
| 916 |
// act & assert |
| 917 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.rinchiToRinchiKey(null, "")); |
| 918 |
Assertions.assertEquals("The argument 'keyType' must not be null.", exception.getMessage()); |
| 919 |
} |
| 920 |
|
| 921 |
@Test |
| 922 |
public void testRinchiToRinchiKey_rinchiIsNull() { |
| 923 |
// act & assert |
| 924 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.rinchiToRinchiKey(RinchiKeyType.LONG, null)); |
| 925 |
Assertions.assertEquals("The argument 'rinchi' must not be null.", exception.getMessage()); |
| 926 |
} |
| 927 |
|
| 928 |
@Test |
| 929 |
public void testRinchiToFileText_rinchiIsNull() { |
| 930 |
// act & assert |
| 931 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.rinchiToFileText(null, "", ReactionFileFormat.AUTO)); |
| 932 |
Assertions.assertEquals("The argument 'rinchi' must not be null.", exception.getMessage()); |
| 933 |
} |
| 934 |
|
| 935 |
@Test |
| 936 |
public void testRinchiToFileText_auxInfoIsNull() { |
| 937 |
// act & assert |
| 938 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.rinchiToFileText("", null, ReactionFileFormat.AUTO)); |
| 939 |
Assertions.assertEquals("The argument 'auxInfo' must not be null.", exception.getMessage()); |
| 940 |
} |
| 941 |
|
| 942 |
@Test |
| 943 |
public void testRinchiToFileText_reactionFileFormatIsNull() { |
| 944 |
// act & assert |
| 945 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.rinchiToFileText("", "", null)); |
| 946 |
Assertions.assertEquals("The argument 'fileFormat' must not be null.", exception.getMessage()); |
| 947 |
} |
| 948 |
|
| 949 |
@Test |
| 950 |
public void testFileTextToRinchiKey_reactionFileTextIsNull() { |
| 951 |
// act & assert |
| 952 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.fileTextToRinchiKey(null, RinchiKeyType.LONG, RinchiOptions.DEFAULT_OPTIONS, ReactionFileFormat.AUTO)); |
| 953 |
Assertions.assertEquals("The argument 'reactionFileText' must not be null.", exception.getMessage()); |
| 954 |
} |
| 955 |
|
| 956 |
@Test |
| 957 |
public void testFileTextToRinchiKey_rinchiKeyTypeIsNull() { |
| 958 |
// act & assert |
| 959 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.fileTextToRinchiKey("", null, RinchiOptions.DEFAULT_OPTIONS, ReactionFileFormat.AUTO)); |
| 960 |
Assertions.assertEquals("The argument 'keyType' must not be null.", exception.getMessage()); |
| 961 |
} |
| 962 |
|
| 963 |
@Test |
| 964 |
public void testFileTextToRinchiKey_optionsIsNull() { |
| 965 |
// act & assert |
| 966 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.fileTextToRinchiKey("", RinchiKeyType.LONG, null, ReactionFileFormat.AUTO)); |
| 967 |
Assertions.assertEquals("The argument 'options' must not be null.", exception.getMessage()); |
| 968 |
} |
| 969 |
|
| 970 |
@Test |
| 971 |
public void testFileTextToRinchiKey_reactionFileFormatIsNull() { |
| 972 |
// act & assert |
| 973 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.fileTextToRinchiKey("", RinchiKeyType.LONG, RinchiOptions.DEFAULT_OPTIONS, null)); |
| 974 |
Assertions.assertEquals("The argument 'fileFormat' must not be null.", exception.getMessage()); |
| 975 |
} |
| 976 |
|
| 977 |
@Test |
| 978 |
public void testFileTextToRinchi_reactionFileTextIsNull() { |
| 979 |
// act & assert |
| 980 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.fileTextToRinchi(null, RinchiOptions.DEFAULT_OPTIONS, ReactionFileFormat.AUTO)); |
| 981 |
Assertions.assertEquals("The argument 'reactionFileText' must not be null.", exception.getMessage()); |
| 982 |
} |
| 983 |
|
| 984 |
@Test |
| 985 |
public void testFileTextToRinchi_optionsIsNull() { |
| 986 |
// act & assert |
| 987 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.fileTextToRinchi("", null, ReactionFileFormat.AUTO)); |
| 988 |
Assertions.assertEquals("The argument 'options' must not be null.", exception.getMessage()); |
| 989 |
} |
| 990 |
|
| 991 |
@Test |
| 992 |
public void testFileTextToRinchi_reactionFileFormatIsNull() { |
| 993 |
// act & assert |
| 994 |
Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> JnaRinchi.fileTextToRinchi("", RinchiOptions.DEFAULT_OPTIONS, null)); |
| 995 |
Assertions.assertEquals("The argument 'fileFormat' must not be null.", exception.getMessage()); |
| 996 |
} |
| 997 |
|
| 998 |
/** |
| 999 |
* Mutable data class for results that are generated when calculating a RInChI (rinchi, auxinfo, rinchiKeyLong, rinchiKeyShort, rinchiKeyWeb). |
| 1000 |
*/ |
| 1001 |
private static class RinchiFullInfo { |
| 1002 |
private String rinchi = null; |
| 1003 |
private String auxInfo = null; |
| 1004 |
private String rinchiKeyLong = null; |
| 1005 |
private String rinchiKeyShort = null; |
| 1006 |
private String rinchiKeyWeb = null; |
| 1007 |
|
| 1008 |
public RinchiFullInfo() { |
| 1009 |
} |
| 1010 |
|
| 1011 |
public String getRinchi() { |
| 1012 |
return rinchi; |
| 1013 |
} |
| 1014 |
|
| 1015 |
public void setRinchi(String rinchi) { |
| 1016 |
this.rinchi = rinchi; |
| 1017 |
} |
| 1018 |
|
| 1019 |
public String getAuxInfo() { |
| 1020 |
return auxInfo; |
| 1021 |
} |
| 1022 |
|
| 1023 |
public void setAuxInfo(String auxInfo) { |
| 1024 |
this.auxInfo = auxInfo; |
| 1025 |
} |
| 1026 |
|
| 1027 |
public String getRinchiKeyLong() { |
| 1028 |
return rinchiKeyLong; |
| 1029 |
} |
| 1030 |
|
| 1031 |
public void setRinchiKeyLong(String rinchiKeyLong) { |
| 1032 |
this.rinchiKeyLong = rinchiKeyLong; |
| 1033 |
} |
| 1034 |
|
| 1035 |
public String getRinchiKeyShort() { |
| 1036 |
return rinchiKeyShort; |
| 1037 |
} |
| 1038 |
|
| 1039 |
public void setRinchiKeyShort(String rinchiKeyShort) { |
| 1040 |
this.rinchiKeyShort = rinchiKeyShort; |
| 1041 |
} |
| 1042 |
|
| 1043 |
public String getRinchiKeyWeb() { |
| 1044 |
return rinchiKeyWeb; |
| 1045 |
} |
| 1046 |
|
| 1047 |
public void setRinchiKeyWeb(String rinchiKeyWeb) { |
| 1048 |
this.rinchiKeyWeb = rinchiKeyWeb; |
| 1049 |
} |
| 1050 |
|
| 1051 |
@Override |
| 1052 |
public String toString() { |
| 1053 |
StringBuilder sb = new StringBuilder(); |
| 1054 |
if (rinchi != null) |
| 1055 |
sb.append("RInChI=").append(rinchi).append("\n"); |
| 1056 |
if (auxInfo != null) |
| 1057 |
sb.append("RAuxInfo=").append(auxInfo).append("\n"); |
| 1058 |
if (rinchiKeyLong != null) |
| 1059 |
sb.append("Long-RInChIKey=").append(rinchiKeyLong).append("\n"); |
| 1060 |
if (rinchiKeyShort != null) |
| 1061 |
sb.append("Short-RInChIKey=").append(rinchiKeyShort).append("\n"); |
| 1062 |
if (rinchiKeyWeb != null) |
| 1063 |
sb.append("Web-RInChIKey=").append(rinchiKeyWeb).append("\n"); |
| 1064 |
return sb.toString(); |
| 1065 |
} |
| 1066 |
} |
| 1067 |
} |