-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxyzGen.java
108 lines (70 loc) · 2.99 KB
/
xyzGen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import org.openscience.cdk.depict.DepictionGenerator;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.modeling.builder3d.ModelBuilder3D;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import java.io.FileWriter;
import java.awt.*;
// sample use
// String smiles = "C(=O)(Cl)Cl";
// String path = "~/Desktop/";
// String format = ".png";
// boolean return2d = true;
// // dipiction(smiles, path, format, false);
// xyzGen gen = new xyzGen(smiles, path, format, return2d);
// gen.dipiction();
public class xyzGen {
public String smiles;
public String path;
public String imgFormat;
public boolean is2d;
public static IAtom[] atoms;
public xyzGen(String Smile, String path, String format, boolean return2d){
smiles = Smile;
this.path = path;
imgFormat = format;
is2d = return2d;
}
public void dipiction() throws Exception{
if (is2d){
System.out.println(path + imgFormat);
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
IAtomContainer mol = smipar.parseSmiles(smiles);
mol.setTitle(smiles);
DepictionGenerator dptgen = new DepictionGenerator();
dptgen.withSize(200, 250).withMolTitle().withTitleColor(Color.DARK_GRAY);
System.out.println(path + mol.getTitle() + imgFormat);
dptgen.depict(mol).writeTo(path + mol.getTitle() + imgFormat);
} else {
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
IAtomContainer mol = smipar.parseSmiles(smiles);
ModelBuilder3D mb3d = ModelBuilder3D.getInstance(bldr);
IAtomContainer coords = mb3d.generate3DCoordinates(mol, false);
try{
int totalAtoms = 0;
for (IAtom atom : coords.atoms()) {
totalAtoms++;
}
// init atom array
atoms = new IAtom[totalAtoms];
// creating atom array
int curAtomIndex = 0;
for (IAtom atom : coords.atoms()) {
atoms[curAtomIndex] = atom;
curAtomIndex++;
}
} catch (Exception e) {}
FileWriter writer = new FileWriter("mol.xyz");
writer.write(smiles + "\n");
writer.write("\n");
for(int i = 0; i < atoms.length; i++){
writer.write(atoms[i].getSymbol() + "\t" + atoms[i].getPoint3d().x + "\t" + atoms[i].getPoint3d().y + "\t" + atoms[i].getPoint3d().z + "\n");
}
writer.close();
}
}
}