org.openmolecules.chem.conf.gen.ConformerSetDiagnostics Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openchemlib Show documentation
Show all versions of openchemlib Show documentation
Open Source Chemistry Library
package org.openmolecules.chem.conf.gen;
import com.actelion.research.chem.Canonizer;
import com.actelion.research.util.DoubleFormat;
import org.openmolecules.chem.conf.so.ConformationRule;
import org.openmolecules.chem.conf.so.SelfOrganizedConformer;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.TreeMap;
public class ConformerSetDiagnostics {
private TreeMap mDiagnosticsMap;
private ConformerGenerator mConformerGenerator;
private RigidFragment[] mRigidFragment;
private RotatableBond[] mRotatableBond;
private String mExitReason;
protected ConformerSetDiagnostics(ConformerGenerator cg) {
mConformerGenerator = cg;
mRotatableBond = cg.getRotatableBonds();
mRigidFragment = cg.getRigidFragments();
mDiagnosticsMap = new TreeMap<>();
}
protected void addNew(TorsionSet ts) {
mDiagnosticsMap.put(ts.getConformer().getName(), new ConformerDiagnostics(ts));
}
public Collection getDiagnostics() {
return mDiagnosticsMap.values();
}
protected ConformerDiagnostics get(TorsionSet ts) {
return mDiagnosticsMap.get(ts.getConformer().getName());
}
protected void setExitReason(String er) {
mExitReason = er;
}
// public int getTorsion(int bond, int index) {
// return mRotatableBond[bond].getTorsion(index);
// }
public int getRotatableBondCount() {
return mRotatableBond.length;
}
public int getRigidFragmentCount() {
return mRigidFragment.length;
}
public double getRigidFragmentLikelyhood(int conformer, int index) {
return mRigidFragment[conformer].getConformerLikelihood(index);
}
// public double getTorsionLikelyhood(int bond, int index) {
// return mRotatableBond[bond].getTorsionLikelyhood(index);
// }
public String getExitReason() {
return mExitReason;
}
public void writeEliminationRuleFile(String path) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), StandardCharsets.UTF_8));
writeDataWarriorHeader(writer, true);
writer.write("Structure\tcoords\tconformer\telim_rules");
writer.newLine();
int conformer = 0;
for (ConformerDiagnostics cd:mDiagnosticsMap.values()) {
writer.write(cd.getIDCode());
writer.write("\t");
writer.write(cd.getCoords());
writer.write("\t");
writer.write(conformer++);
writer.write("\t");
for (String rule:cd.getEliminationRules()) {
writer.write(rule);
writer.write("");
}
writer.write("\n");
}
writeDataWarriorFooter(writer);
writer.close();
}
catch (IOException ioe) {}
}
public void writePermutationSpace(String fileName) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8));
writer.write("rigid fragments");
for (int i=1; i<=mRotatableBond.length; i++)
writer.write("\ttorsion "+i);
writer.write("\telimination rules\tconformers tried");
writer.newLine();
for (int[] rigidFragmentIndex:mConformerGenerator.getBaseConformerMap().keySet()) {
for (int rfi:rigidFragmentIndex)
writer.write(rfi+" ");
writer.write("\t");
BaseConformer bc = mConformerGenerator.getBaseConformer(rigidFragmentIndex);
for (int rb=0; rb");
}
}
TorsionSetEncoder encoder = mConformerGenerator.getTorsionSetStrategy().getTorsionSetEncoder();
for (TorsionSetEliminationRule er: bc.getEliminationRules()) {
writer.write(encoder.createRuleString(er, bc));
writer.write("");
}
writer.write("\t"+bc.getDerivedConformerCount());
writer.newLine();
}
writeDataWarriorFooter(writer);
writer.close();
}
catch (IOException ioe) {}
}
public void writeAllConformersFile(String fileName) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8));
writeDataWarriorHeader(writer, true);
writer.write("Structure\tcoords\tname\tsuccess\tlikelihood\tcollision");
for (int i=1; i<=mRigidFragment.length; i++)
writer.write("\tfragment "+i);
for (int i=1; i<=mRotatableBond.length; i++)
writer.write("\ttorsion "+i);
writer.write("\tnew elimination rules");
writer.newLine();
for (ConformerDiagnostics cd:mDiagnosticsMap.values()) {
writer.write(cd.getIDCode() + "\t" + cd.getCoords() + "\t" + cd.getName() + "\t" + (cd.isSuccess() ? "yes" : "no") + "\t" + DoubleFormat.toString(cd.getLikelihood(),3) + "\t" + DoubleFormat.toString(cd.getCollisionIntensity(),3));
int[] ci = cd.getRigidFragmentIndexes();
for (int rf=0; rfoptimized:"+fixedTorsion);
}
writer.write("\t");
for (String rule:cd.getEliminationRules()) {
writer.write(rule);
writer.write("");
}
writer.newLine();
}
writeDataWarriorFooter(writer);
writer.close();
}
catch (IOException ioe) {}
}
public void writeRigidFragmentFile(String path) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), StandardCharsets.UTF_8));
writeDataWarriorHeader(writer, true);
writer.write("Structure\tcoords\tfragment\tconformer\tlikelyhood\trule strain\tatom strain");
writer.newLine();
for (int i=0; i");
}
for (int a=0; a");
}
writer.newLine();
}
}
writeDataWarriorFooter(writer);
writer.close();
}
catch (IOException ioe) {}
}
public void writeRotatableBondsFile(String path) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), StandardCharsets.UTF_8));
writeDataWarriorHeader(writer, false);
writer.write("Structure\ttorsion-ID\tfragments\ttorsions\tfrequenies\trelevance");
writer.newLine();
for (int i=0; i");
}
for (int j=0; j");
}
writer.write(DoubleFormat.toString(rb.getRelevance(),3));
writer.newLine();
}
writeDataWarriorFooter(writer);
writer.close();
}
catch (IOException ioe) {}
}
private void writeDataWarriorHeader(BufferedWriter writer, boolean includeCoords) throws IOException {
writer.write("");
writer.newLine();
writer.write("");
writer.newLine();
writer.write("");
writer.newLine();
if (includeCoords) {
writer.write("");
writer.newLine();
writer.write("");
writer.newLine();
writer.write("");
writer.newLine();
}
writer.write(" ");
writer.newLine();
}
private void writeDataWarriorFooter(BufferedWriter writer) throws IOException {
writer.write("");
writer.newLine();
writer.write("");
writer.newLine();
writer.write(" ");
writer.newLine();
}
}