The name MInChI now refers to the
Mixture InChI
This Java code generates MInChI from InChI and vice versa.
It may be used under the terms of the Artistic License.
import java.io.*;
/**
* This class turns an InChI string into a MInChI string, and vice versa
*
*
*@author Jonathan M Goodman, Department of Chemistry, University of Cambridge, UK. jmg11@cam.ac.uk
*@created 2006
*/
class MInChI {
/**
* This class turns an InChI string into a MInChI string, and vice-versa
*
*/
public static void main(String[] args) {
String output = "";
String outputmain = " ";
String encode = "shclrmpqda";
String decode = "/-,();+?.*";
boolean inchi2minchi = true;
boolean header = true;
boolean firstheader = true;
int i = 0;
int j = 0;
int k = -1;
System.out.println("(c) J M Goodman, 2006");
System.out.println("Cambridge University");
System.out.println("");
if (args[0].toLowerCase().indexOf("minchi") >= 0) {
inchi2minchi = false;
}
if (inchi2minchi) {
// converting inchi to minchi
output = "MInChI";
i = args[0].length();
for (j = 5; j < i; j++) {
if (args[0].charAt(j) == '=') {
output += "xe";
} else if (header) {
if (args[0].charAt(j) == '.') {
output += " ";
} else if (args[0].charAt(j) == '/') {
if (firstheader) {
firstheader = false;
output += " ";
} else {
header = false;
}
} else {
output += args[0].charAt(j);
}
} else {
k++;
if ((k / 12) * 12 == k) {
k = 0;
output += " ";
}
if (decode.indexOf(args[0].charAt(j)) >= 0) {
output += "x";
k++;
if ((k / 12) * 12 == k) {
k = 0;
output += " ";
}
output += encode.charAt(decode.indexOf(args[0].charAt(j)));
} else {
output += args[0].charAt(j);
}
}
}
} else {
// converting minchi to inchi
output = "InChI=" + args[0].substring(8) + "/";
i = args.length;
for (j = 1; j < i; j++) {
if (header) {
output += args[j];
if (args.length > j + 1) {
if (args[j + 1].indexOf("x") >= 0) {
output += "/";
header = false;
} else {
output += ".";
}
}
} else {
outputmain += args[j];
outputmain = outputmain.trim();
}
}
j = 0;
while (j < outputmain.length()) {
if (outputmain.charAt(j) == 'x') {
j++;
output += decode.charAt(encode.indexOf(outputmain.charAt(j)));
} else {
output += outputmain.charAt(j);
}
j++;
}
}
System.out.println(output);
}
}
|