summaryrefslogtreecommitdiff
path: root/java/LoaelMazzatorta.java
blob: 77279e2e67d0012e593d48e43d191ac364186aab (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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import insilico.core.descriptor.Descriptor;
import insilico.core.descriptor.DescriptorBlock;
import insilico.core.descriptor.blocks.AtomCenteredFragments;
import insilico.core.descriptor.blocks.Constitutional;
import insilico.core.descriptor.blocks.FunctionalGroups;
import insilico.core.descriptor.blocks.logp.MLogP;
import insilico.core.exception.DescriptorNotFoundException;
import insilico.core.molecule.InsilicoMolecule;
import insilico.core.molecule.conversion.file.MoleculeFileSmiles;
import java.util.ArrayList;

/**
 * Descriptors needed by Nestle' models, based on VEGA core descriptor with
 * some modification in order to be compliant with older Dragon descriptors
 * used in their original model.
 * 
 * @author Alberto Manganaro (a.manganaro@kode-solutions.net)
 * modified by helma@in-silico.ch
 */
public class LoaelMazzatorta {

    
    public LoaelMazzatorta() {
        
    }
    
    
    /**
     * Main method to calculate the descriptors, from a given input file 
     * containing just the SMILES of the molecules. The results are written
     * in a tab-separated text file.
     * 
     * @param InputFile full path+filename of the input file (with the SMILES
     * to be processed)
     * @param OutFile full path+filename of the file to be written with the
     * calculated descriptors
     */
    public void Calculate(String InputFile) {
        
        ArrayList<InsilicoMolecule> mols;
        
        MoleculeFileSmiles sfile = new MoleculeFileSmiles();
        try {
            sfile.OpenFile(InputFile);
            mols = sfile.ReadAll();        
        } catch (Throwable ex) {
            System.out.println("Unable to read and import molecules - " + ex.getMessage());
            return;
        }
                               
        // build descriptors blocks
        AtomCenteredFragments b_acf = new AtomCenteredFragments();
        Constitutional b_const = new Constitutional();
        FunctionalGroups b_func = new FunctionalGroups();
        MLogP b_mlogp = new MLogP();
        
        // run calculation
        int idx = 0;
        int dNum = 0;
        int nErr = 0;
        for (InsilicoMolecule m  : mols) {

            idx++;
            
            // check mol
            if (!m.IsValid()) {
                nErr++;
                System.out.println("INVALID MOLECULE\t" + idx);
                continue;
            }
            
            // calculate
            b_mlogp.Calculate(m);
            b_const.Calculate(m);
            b_func.Calculate(m);
            b_acf.Calculate(m);
            CustomDescriptors otherDesc = new CustomDescriptors(m);
            
            double MLogP;
            try {
                MLogP = b_mlogp.GetByName("MLogP").getValue();
                MLogP = MLogP + otherDesc.N_MlogP_Correction * (-3.684);
            } catch (DescriptorNotFoundException ex) {
                MLogP = -999;
            }
            
            double MLogP_square = -999;
            if (MLogP != -999)
                MLogP_square = Math.pow(MLogP,2);
            
            double log10_loael = 1.80710
              + 0.05150*otherDesc.RBN
              - 0.16676*getDescriptor(b_const, "nN")
              - 0.91947*otherDesc.nHM
              - 0.11135*getDescriptor(b_const, "nX")
              - 0.09491*getDescriptor(b_func, "nCt")
              + 0.68498*getDescriptor(b_func, "nArCOOH")
              + 0.46493*getDescriptor(b_func, "nOHp")
              - 0.13636*getDescriptor(b_func, "nArOR")
              - 0.32953*getDescriptor(b_func, "nRSR")
              - 1.78510*getDescriptor(b_func, "nSO")
              - 0.50694*getDescriptor(b_func, "nCXr=")
              + 0.52406*getDescriptor(b_func, "nCconjX")
              - 0.02561*getDescriptor(b_acf, "H-052")
              - 0.16168*getDescriptor(b_acf, "H-054")
              + 0.17824*getDescriptor(b_acf, "O-058")
              - 0.26345*getDescriptor(b_acf, "S-107")
              - 1.36840*getDescriptor(b_acf, "P-117")
              + 0.13760*otherDesc.Hy
              + 0.07871*MLogP
              - 0.02219*MLogP_square;

            System.out.println(log10_loael);
            
       }
        
    }


    private double getDescriptor(DescriptorBlock block, String name) {
        double res;
        try {
            res = Double.parseDouble(block.GetByName(name).getFormattedValue());
        } catch (DescriptorNotFoundException e) {
            return -999;
        }
        return res;
    }
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        LoaelMazzatorta loael = new LoaelMazzatorta();
        loael.Calculate(args[0]);
    }
    
}