| 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 static org.junit.jupiter.api.Assertions.assertEquals; |
| 21 |
|
| 22 |
import org.junit.jupiter.api.Test; |
| 23 |
|
| 24 |
import io.github.dan2097.jnainchi.InchiAtom; |
| 25 |
import io.github.dan2097.jnainchi.InchiBond; |
| 26 |
import io.github.dan2097.jnainchi.InchiBondType; |
| 27 |
import io.github.dan2097.jnainchi.InchiRadical; |
| 28 |
|
| 29 |
/** |
| 30 |
* Testing the functionality/utilities concerning RinchiInput. |
| 31 |
*/ |
| 32 |
public class TestRinchiInput { |
| 33 |
|
| 34 |
/** |
| 35 |
* Testing benzene represented as a kekule structure |
| 36 |
*/ |
| 37 |
@Test |
| 38 |
public void testBezene01() { |
| 39 |
RinchiInput rInp = new RinchiInput(); |
| 40 |
RinchiInputComponent ric1 = new RinchiInputComponent(); |
| 41 |
rInp.addComponent(ric1); |
| 42 |
ric1.setRole(ReactionComponentRole.REAGENT); |
| 43 |
InchiAtom at1 = new InchiAtom("C"); |
| 44 |
InchiAtom at2 = new InchiAtom("C"); |
| 45 |
InchiAtom at3 = new InchiAtom("C"); |
| 46 |
InchiAtom at4 = new InchiAtom("C"); |
| 47 |
InchiAtom at5 = new InchiAtom("C"); |
| 48 |
InchiAtom at6 = new InchiAtom("C"); |
| 49 |
ric1.addAtom(at1); |
| 50 |
ric1.addAtom(at2); |
| 51 |
ric1.addAtom(at3); |
| 52 |
ric1.addAtom(at4); |
| 53 |
ric1.addAtom(at5); |
| 54 |
ric1.addAtom(at6); |
| 55 |
ric1.addBond(new InchiBond(at1, at2, InchiBondType.SINGLE)); |
| 56 |
ric1.addBond(new InchiBond(at2, at3, InchiBondType.DOUBLE)); |
| 57 |
ric1.addBond(new InchiBond(at3, at4, InchiBondType.SINGLE)); |
| 58 |
ric1.addBond(new InchiBond(at4, at5, InchiBondType.DOUBLE)); |
| 59 |
ric1.addBond(new InchiBond(at5, at6, InchiBondType.SINGLE)); |
| 60 |
ric1.addBond(new InchiBond(at6, at1, InchiBondType.DOUBLE)); |
| 61 |
|
| 62 |
RinchiOutput rOutput = JnaRinchi.toRinchi(rInp); |
| 63 |
assertEquals("RInChI=1.00.1S/<>C6H6/c1-2-4-6-5-3-1/h1-6H/d-", rOutput.getRinchi(), "RInChI for benzene"); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Testing benzene represented 'aromatic' bonds |
| 68 |
*/ |
| 69 |
@Test |
| 70 |
public void testBezene02() { |
| 71 |
RinchiInput rInp = new RinchiInput(); |
| 72 |
RinchiInputComponent ric1 = new RinchiInputComponent(); |
| 73 |
rInp.addComponent(ric1); |
| 74 |
ric1.setRole(ReactionComponentRole.REAGENT); |
| 75 |
InchiAtom at1 = new InchiAtom("C"); |
| 76 |
InchiAtom at2 = new InchiAtom("C"); |
| 77 |
InchiAtom at3 = new InchiAtom("C"); |
| 78 |
InchiAtom at4 = new InchiAtom("C"); |
| 79 |
InchiAtom at5 = new InchiAtom("C"); |
| 80 |
InchiAtom at6 = new InchiAtom("C"); |
| 81 |
ric1.addAtom(at1); |
| 82 |
ric1.addAtom(at2); |
| 83 |
ric1.addAtom(at3); |
| 84 |
ric1.addAtom(at4); |
| 85 |
ric1.addAtom(at5); |
| 86 |
ric1.addAtom(at6); |
| 87 |
ric1.addBond(new InchiBond(at1, at2, InchiBondType.ALTERN)); |
| 88 |
ric1.addBond(new InchiBond(at2, at3, InchiBondType.ALTERN)); |
| 89 |
ric1.addBond(new InchiBond(at3, at4, InchiBondType.ALTERN)); |
| 90 |
ric1.addBond(new InchiBond(at4, at5, InchiBondType.ALTERN)); |
| 91 |
ric1.addBond(new InchiBond(at5, at6, InchiBondType.ALTERN)); |
| 92 |
ric1.addBond(new InchiBond(at6, at1, InchiBondType.ALTERN)); |
| 93 |
|
| 94 |
RinchiOutput rOutput = JnaRinchi.toRinchi(rInp); |
| 95 |
assertEquals("RInChI=1.00.1S/<>C6H6/c1-2-4-6-5-3-1/h1-6H/d-", rOutput.getRinchi(), "RInChI for benzene"); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
/** |
| 100 |
* Testing a structure with radical (propane radical) |
| 101 |
*/ |
| 102 |
@Test |
| 103 |
public void testRadical01() { |
| 104 |
RinchiInput rInp = new RinchiInput(); |
| 105 |
RinchiInputComponent ric1 = new RinchiInputComponent(); |
| 106 |
rInp.addComponent(ric1); |
| 107 |
ric1.setRole(ReactionComponentRole.REAGENT); |
| 108 |
InchiAtom at1 = new InchiAtom("C"); |
| 109 |
at1.setRadical(InchiRadical.DOUBLET); |
| 110 |
InchiAtom at2 = new InchiAtom("C"); |
| 111 |
InchiAtom at3 = new InchiAtom("C"); |
| 112 |
ric1.addAtom(at1); |
| 113 |
ric1.addAtom(at2); |
| 114 |
ric1.addAtom(at3); |
| 115 |
ric1.addBond(new InchiBond(at1, at2, InchiBondType.SINGLE)); |
| 116 |
ric1.addBond(new InchiBond(at2, at3, InchiBondType.SINGLE)); |
| 117 |
|
| 118 |
RinchiOutput rOutput = JnaRinchi.toRinchi(rInp); |
| 119 |
assertEquals("RInChI=1.00.1S/<>C3H7/c1-3-2/h1,3H2,2H3/d-", rOutput.getRinchi(), "RInChI for propan radical"); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Testing a structure with one radical |
| 124 |
*/ |
| 125 |
@Test |
| 126 |
public void testRadical02() { |
| 127 |
RinchiInputFromRinchiOutput rInpOut = JnaRinchi.getRinchiInputFromRinchi( |
| 128 |
"RInChI=1.00.1S/<>C3H7/c1-3-2/h1,3H2,2H3/d-", |
| 129 |
"RAuxInfo=1.00.1/<>0/N:1,3,2/CRV:1d/rA:3nC.2CC/rB:s1;s2;/rC:;;;"); |
| 130 |
RinchiInput rInp = rInpOut.getRinchiInput(); |
| 131 |
int nDoublets = 0; |
| 132 |
for (int i = 0; i < rInp.getComponents().get(0).getAtoms().size(); i++) |
| 133 |
if (rInp.getComponents().get(0).getAtom(i).getRadical() == InchiRadical.DOUBLET) |
| 134 |
nDoublets++; |
| 135 |
|
| 136 |
assertEquals(1, nDoublets, "Number of doublet radicals"); |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Testing a structure with two radicals |
| 141 |
*/ |
| 142 |
@Test |
| 143 |
public void testRadical03() { |
| 144 |
RinchiInputFromRinchiOutput rInpOut = JnaRinchi.getRinchiInputFromRinchi( |
| 145 |
"RInChI=1.00.1S/<>C3H6/c1-3-2/h1-3H2/d-", |
| 146 |
"RAuxInfo=1.00.1/<>0/N:1,3,2/E:(1,2)/CRV:1d,2d/rA:3nC.2CC.2/rB:s1;s2;/rC:;;;"); |
| 147 |
RinchiInput rInp = rInpOut.getRinchiInput(); |
| 148 |
int nDoublets = 0; |
| 149 |
for (int i = 0; i < rInp.getComponents().get(0).getAtoms().size(); i++) |
| 150 |
if (rInp.getComponents().get(0).getAtom(i).getRadical() == InchiRadical.DOUBLET) |
| 151 |
nDoublets++; |
| 152 |
|
| 153 |
assertEquals(2, nDoublets, "Number of doublet radicals"); |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Testing a compound with a triplet radical |
| 158 |
*/ |
| 159 |
@Test |
| 160 |
public void testRadical04() { |
| 161 |
RinchiInput rInp = new RinchiInput(); |
| 162 |
RinchiInputComponent ric1 = new RinchiInputComponent(); |
| 163 |
rInp.addComponent(ric1); |
| 164 |
ric1.setRole(ReactionComponentRole.REAGENT); |
| 165 |
InchiAtom at1 = new InchiAtom("C"); |
| 166 |
//SINGKET and TRIPLET generate the same RInChI and RAuxInfo !!! |
| 167 |
at1.setRadical(InchiRadical.TRIPLET); |
| 168 |
InchiAtom at2 = new InchiAtom("C"); |
| 169 |
InchiAtom at3 = new InchiAtom("C"); |
| 170 |
ric1.addAtom(at1); |
| 171 |
ric1.addAtom(at2); |
| 172 |
ric1.addAtom(at3); |
| 173 |
ric1.addBond(new InchiBond(at1, at2, InchiBondType.SINGLE)); |
| 174 |
ric1.addBond(new InchiBond(at2, at3, InchiBondType.SINGLE)); |
| 175 |
|
| 176 |
RinchiOutput rOutput = JnaRinchi.toRinchi(rInp); |
| 177 |
assertEquals("RInChI=1.00.1S/<>C3H6/c1-3-2/h1H,3H2,2H3/d-", rOutput.getRinchi(), "RInChI for propan radical"); |
| 178 |
} |
| 179 |
} |