summaryrefslogtreecommitdiff
path: root/java/JoelibDescriptors.java
blob: e90e35f9812f138a81d58918fa7c63d42947e1ae (plain)
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
import java.util.*;
import java.io.*;
import joelib2.feature.Feature;
import joelib2.feature.FeatureHelper;
import joelib2.feature.FeatureFactory;
import joelib2.feature.FeatureResult;
import joelib2.io.BasicIOType;
import joelib2.io.BasicIOTypeHolder;
import joelib2.io.BasicReader;
import joelib2.io.MoleculeFileHelper;
import joelib2.io.MoleculeFileIO;
import joelib2.io.MoleculeIOException;
import joelib2.molecule.BasicConformerMolecule;

class JoelibDescriptors {
  public static void main(String[] args) {

    String[] features = null;
    features = new String[args.length-1];
    System.arraycopy(args,1,features,0,args.length-1);

    FeatureFactory factory = FeatureFactory.instance();
    MoleculeFileIO loader = null;
    String line = new String();
    String sdf = new String();
    try {
      // parse 3d sdf from file and calculate descriptors
      InputStream is = new FileInputStream(args[0]);
      PrintWriter yaml = new PrintWriter(new FileWriter(args[0]+"joelib.yaml"));
      BasicIOType inType = BasicIOTypeHolder.instance().getIOType("SDF");
      loader = MoleculeFileHelper.getMolReader(is, inType);
      BasicConformerMolecule mol = new BasicConformerMolecule(inType, inType);
      while (true) {
        try {
          Boolean success = loader.read(mol);
          if (!success) { break; } // last molecule
          for (int i =0; i < features.length; i++) {
            String name = "joelib2.feature.types." + features[i];
            Feature feature = factory.getFeature(name);
            FeatureResult result = feature.calculate(mol);
            if (i == 0) { yaml.print("- "); }
            else { yaml.print("  "); }
            yaml.print( "Joelib."+features[i]+": " );
            yaml.println( result.toString() );
          }

        }
        catch (Exception e) { 
          System.err.println(e.toString());
          e.printStackTrace();
        }
      }
      yaml.close();
    }
    catch (Exception e) {
      System.err.println(e.toString());
      e.printStackTrace();
    }
  }
}