| 1 |
/** |
| 2 |
* JNA-InChI - Library for calling InChI from Java |
| 3 |
* Copyright © 2018 Daniel Lowe |
| 4 |
* |
| 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 |
* |
| 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 |
* |
| 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.jnainchi; |
| 19 |
|
| 20 |
public class InchiStereo { |
| 21 |
|
| 22 |
/** |
| 23 |
* Use when a stereocentre's configuration references an implicit hydrogen |
| 24 |
*/ |
| 25 |
public static final InchiAtom STEREO_IMPLICIT_H = new InchiAtom("H"); |
| 26 |
|
| 27 |
private final InchiAtom[] atoms; |
| 28 |
private final InchiAtom centralAtom; |
| 29 |
private final InchiStereoType type; |
| 30 |
private final InchiStereoParity parity; |
| 31 |
|
| 32 |
|
| 33 |
InchiStereo(InchiAtom[] atoms, InchiAtom centralAtom, InchiStereoType type, InchiStereoParity parity) { |
| 34 |
if (atoms == null) { |
| 35 |
throw new IllegalArgumentException("atoms was null"); |
| 36 |
} |
| 37 |
if (type == null) { |
| 38 |
throw new IllegalArgumentException("type was null"); |
| 39 |
} |
| 40 |
if (parity == null) { |
| 41 |
throw new IllegalArgumentException("parity was null"); |
| 42 |
} |
| 43 |
if (atoms.length != 4) { |
| 44 |
throw new IllegalArgumentException("Atoms array should be length 4"); |
| 45 |
} |
| 46 |
for (int i = 0; i < atoms.length; i++) { |
| 47 |
if (atoms[i] == null) { |
| 48 |
throw new IllegalArgumentException("Atom at index " + i + " was null, use STEREO_IMPLICIT_H for implicit hydrogen, and the atom with a lone pair for lone pairs"); |
| 49 |
} |
| 50 |
} |
| 51 |
if (type != InchiStereoType.DoubleBond && centralAtom == null) { |
| 52 |
throw new IllegalArgumentException("centralAtom was null"); |
| 53 |
} |
| 54 |
this.atoms = atoms; |
| 55 |
this.centralAtom = centralAtom; |
| 56 |
this.type = type; |
| 57 |
this.parity = parity; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Defines the stereo configuration around the give centralAtom. The four vertexes of the tetrahedral centre should be given along with the parity. |
| 62 |
* If one of the vertexes is an implicit hydrogen use {@link #STEREO_IMPLICIT_H}. If one is a lone pair, use the centralAtom for this vertex |
| 63 |
* @param centralAtom |
| 64 |
* @param atom1 |
| 65 |
* @param atom2 |
| 66 |
* @param atom3 |
| 67 |
* @param atom4 |
| 68 |
* @param parity |
| 69 |
* @return |
| 70 |
*/ |
| 71 |
public static InchiStereo createTetrahedralStereo(InchiAtom centralAtom, InchiAtom atom1, InchiAtom atom2, InchiAtom atom3, InchiAtom atom4, InchiStereoParity parity) { |
| 72 |
return new InchiStereo(new InchiAtom[] {atom1, atom2, atom3, atom4}, centralAtom, InchiStereoType.Tetrahedral, parity); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* <pre> |
| 77 |
* Given |
| 78 |
* A E |
| 79 |
* \ / |
| 80 |
* C = D |
| 81 |
* / \ |
| 82 |
* B F |
| 83 |
* |
| 84 |
* atom1 is A (or B) |
| 85 |
* atom2 is C |
| 86 |
* atom3 is D |
| 87 |
* atom4 is E (or F) |
| 88 |
* and the parity is whether atom1 and atom2 are on the same side; {@link InchiStereoParity#ODD} if on the same side |
| 89 |
* Atom1/2 should be chosen such that neither are implicit hydrogen |
| 90 |
* |
| 91 |
* For a cumulene (NOTE stereochemistry on cumulenes with more than 3 double bonds are unsupported by InChI) |
| 92 |
* Given |
| 93 |
* A G |
| 94 |
* \ / |
| 95 |
* C = D = E = F |
| 96 |
* / \ |
| 97 |
* B H |
| 98 |
* |
| 99 |
* atom1 is A (or B) |
| 100 |
* atom2 is D |
| 101 |
* atom3 is E |
| 102 |
* atom4 is G (or H) |
| 103 |
* |
| 104 |
* Atom1/2 should be chosen such that neither are implicit hydrogen |
| 105 |
* |
| 106 |
* For the 2 adjacent double-bond case use {@link InchiStereo#createAllenalStereo(InchiAtom, InchiAtom, InchiAtom, InchiAtom, InchiAtom, InchiStereoParity)} |
| 107 |
* </pre> |
| 108 |
* @param atom1 |
| 109 |
* @param atom2 |
| 110 |
* @param atom3 |
| 111 |
* @param atom4 |
| 112 |
* @param parity |
| 113 |
* @return |
| 114 |
*/ |
| 115 |
public static InchiStereo createDoubleBondStereo(InchiAtom atom1, InchiAtom atom2, InchiAtom atom3, InchiAtom atom4, InchiStereoParity parity) { |
| 116 |
if (STEREO_IMPLICIT_H == atom1 || STEREO_IMPLICIT_H == atom2|| STEREO_IMPLICIT_H == atom3 || STEREO_IMPLICIT_H == atom4) { |
| 117 |
throw new IllegalArgumentException("Double bond stereo should use non-implicit hydrogn atoms"); |
| 118 |
} |
| 119 |
return new InchiStereo(new InchiAtom[] {atom1, atom2, atom3, atom4}, null, InchiStereoType.DoubleBond, parity); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* <pre> |
| 124 |
* Defines the stereo configuration of an allenal stereocentre, these behave like an extended tetrahedron. |
| 125 |
* The four vertexes of the tetrahedron should be given along with the parity. |
| 126 |
* If one of the vertexes is an implicit hydrogen use {@link #STEREO_IMPLICIT_H}. |
| 127 |
* |
| 128 |
* Given |
| 129 |
* A F |
| 130 |
* \ / |
| 131 |
* C = D = E |
| 132 |
* / \ |
| 133 |
* B G |
| 134 |
* |
| 135 |
* centralAtom is D |
| 136 |
* atom1 is A |
| 137 |
* atom2 is B |
| 138 |
* atom3 is F |
| 139 |
* atom4 is G |
| 140 |
* |
| 141 |
* (NOTE allenal centers with more than 2 double bonds are unsupported by InChI) |
| 142 |
* </pre> |
| 143 |
* @param centralAtom |
| 144 |
* @param atom1 |
| 145 |
* @param atom2 |
| 146 |
* @param atom3 |
| 147 |
* @param atom4 |
| 148 |
* @param parity |
| 149 |
* @return |
| 150 |
*/ |
| 151 |
public static InchiStereo createAllenalStereo(InchiAtom centralAtom, InchiAtom atom1, InchiAtom atom2, InchiAtom atom3, InchiAtom atom4, InchiStereoParity parity) { |
| 152 |
return new InchiStereo(new InchiAtom[] {atom1, atom2, atom3, atom4}, centralAtom, InchiStereoType.Allene, parity); |
| 153 |
} |
| 154 |
|
| 155 |
public InchiAtom[] getAtoms() { |
| 156 |
return atoms; |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Null for {@link InchiStereoType#DoubleBond} |
| 161 |
* @return |
| 162 |
*/ |
| 163 |
public InchiAtom getCentralAtom() { |
| 164 |
return centralAtom; |
| 165 |
} |
| 166 |
|
| 167 |
public InchiStereoType getType() { |
| 168 |
return type; |
| 169 |
} |
| 170 |
|
| 171 |
public InchiStereoParity getParity() { |
| 172 |
return parity; |
| 173 |
} |
| 174 |
|
| 175 |
} |