public void addResidue(String name, String chain, String loc) { Variable var; if (titratableResNames.contains(name)) { String[] labels = resToTaut.get(name); // for (int i=0; i<labels.length; i++){ // labels[i] = labels[i]+"_"+chain+"_"+loc; // } var = new Variable(name + "_" + chain + "_" + loc, labels); for (String l : labels) { Instance vl = var.getInstance(l); if (tRes.contains(l)) { vl.setEnergy(modPka.get(l)); } else { vl.setEnergy(0); } } } else { nonTitratableResNames.add(name); String[] label = {name}; var = new Variable(name + "_" + chain + "_" + loc, label); Instance vl = var.getInstance(label[0]); vl.setEnergy(0); } addResidue(var); }
public void printProtein() { System.out.println(); System.out.println("*****************"); System.out.println("* PROTEIN *"); System.out.println("*****************"); for (Variable v : residues) { System.out.println(v.toString()); for (Instance i : v.getInstances()) { System.out.println(" " + i.toString() + " with energy " + i.getEnergy()); } } System.out.println(); }
public void printEnergy() { System.out.println(); System.out.println("*****************"); System.out.println("* ENERGY *"); System.out.println("*****************"); for (Variable v1 : residues) { for (Instance i1 : v1.getInstances()) { for (Variable v2 : residues) { if (v1.equals(v2)) { continue; } for (Instance i2 : v2.getInstances()) { System.out.println(i1.toString() + ", " + i2.toString() + " " + bi.get(i1, i2)); } } } } }
public Instance getInstance(String name, String chain, String loc) { String chainLoc = chain + "_" + loc; int endLength = chainLoc.length(); for (Variable v : residues) { String nm = v.getName(); if (chainLoc.equals(nm.substring(nm.length() - endLength))) { for (Instance i : v.getInstances()) { if (i.getLabel().equals(name)) { return i; } } } } return null; // String[] tauts; // if (titratableResNames.contains(name)){ // tauts = resToTaut.get(name); // // }else{ // tauts = new String[1]; // tauts[0] = name; // } // for (Variable r: residues){ // for (int j=0; j<tauts.length; j++){ // if (r.getName().equals(tauts[j]+"_"+chain+"_"+loc)){ // for (Instance i: r.getInstances()){ // if (i.getLabel().equals(name)){ // return i; // } // } // } // } // } // return null; }
public void makeBiGr(WriteFile wr) { if (!checkBinary()) { System.out.println("Can't do binary graph cut, Systm isn't binary."); } else { sys.makeNF(); wr.writeln("REGULAR ENERGIES"); // binary for (Variable var1 : sys.getVars()) { for (Instance inst1 : var1.getInstances()) { for (Variable var2 : sys.getVars()) { if (var1.equals(var2)) continue; for (Instance inst2 : var2.getInstances()) { if (inst1.getLabel().equals("PROT") && inst2.getLabel().equals("PROT")) { wr.writeln( "(" + inst1.getName() + "_PROTONATED, " + inst2.getName() + "_PROTONATED) " + Math.round(sys.getBinary().get(inst1, inst2) * 10000.0) / 10000.0); } else if (inst1.getLabel().equals("PROT") && inst2.getLabel().equals("DEPROT")) { wr.writeln( "(" + inst1.getName() + "_PROTONATED, " + inst2.getName() + "_DEPROTONATED) " + Math.round(sys.getBinary().get(inst1, inst2) * 10000.0) / 10000.0); } else if (inst1.getLabel().equals("DEPROT") && inst2.getLabel().equals("PROT")) { wr.writeln( "(" + inst1.getName() + "_DEPROTONATED, " + inst2.getName() + "_PROTONATED) " + Math.round(sys.getBinary().get(inst1, inst2) * 10000.0) / 10000.0); } else if (inst1.getLabel().equals("DEPROT") && inst2.getLabel().equals("DEPROT")) { wr.writeln( "(" + inst1.getName() + "_DEPROTONATED, " + inst2.getName() + "_DEPROTONATED) " + Math.round(sys.getBinary().get(inst1, inst2) * 10000.0) / 10000.0); } } } } } // Set<Vector<Instance>> keys = sys.getBinary().keySet(); // for (Vector<Instance> key : keys){ // Instance key1 = key.get(0); // Instance key2 = key.get(1); // if (key1.getLabel().equals("PROT") && key2.getLabel().equals("PROT")){ // wr.writeln("("+key1.getName()+"_PROTONATED, "+key2.getName()+"_PROTONATED) // "+Math.round(sys.getBinary().get(key1, key2)*10000.0)/10000.0); // }else if (key1.getLabel().equals("PROT") && key2.getLabel().equals("DEPROT")){ // wr.writeln("("+key1.getName()+"_PROTONATED, "+key2.getName()+"_DEPROTONATED) // "+Math.round(sys.getBinary().get(key1, key2)*10000.0)/10000.0); // }else if (key1.getLabel().equals("DEPROT") && key2.getLabel().equals("PROT")){ // wr.writeln("("+key1.getName()+"_DEPROTONATED, "+key2.getName()+"_PROTONATED) // "+Math.round(sys.getBinary().get(key1, key2)*10000.0)/10000.0); // }else{ // wr.writeln("("+key1.getName()+"_DEPROTONATED, "+key2.getName()+"_DEPROTONATED) // "+Math.round(sys.getBinary().get(key1, key2)*10000.0)/10000.0); // } // } // unary for (Variable var : sys.getVars()) { for (Instance inst : var.getInstances()) { if (inst.getLabel().equals("PROT")) { wr.writeln( inst.getName() + "_PROTONATED " + Math.round(inst.getEnergy() * 10000.0) / 10000.0); } else if (inst.getLabel().equals("DEPROT")) { wr.writeln( inst.getName() + "_DEPROTONATED " + Math.round(inst.getEnergy() * 10000.0) / 10000.0); } else { wr.writeln( inst.toString() + "_OTHER " + Math.round(inst.getEnergy() * 10000.0) / 10000.0); } } } wr.writeln(); wr.writeln("NORMAL FORM ENERGIES"); // binary for (Variable var1 : sys.getVars()) { for (Instance inst1 : var1.getInstances()) { for (Variable var2 : sys.getVars()) { if (var1.equals(var2)) continue; for (Instance inst2 : var2.getInstances()) { if (inst1.getLabel().equals("PROT") && inst2.getLabel().equals("PROT")) { wr.writeln( "(" + inst1.getName() + "_PROTONATED, " + inst2.getName() + "_PROTONATED) " + Math.round(sys.getBinaryNF().get(inst1, inst2) * 10000.0) / 10000.0); } else if (inst1.getLabel().equals("PROT") && inst2.getLabel().equals("DEPROT")) { wr.writeln( "(" + inst1.getName() + "_PROTONATED, " + inst2.getName() + "_DEPROTONATED) " + Math.round(sys.getBinaryNF().get(inst1, inst2) * 10000.0) / 10000.0); } else if (inst1.getLabel().equals("DEPROT") && inst2.getLabel().equals("PROT")) { wr.writeln( "(" + inst1.getName() + "_DEPROTONATED, " + inst2.getName() + "_PROTONATED) " + Math.round(sys.getBinaryNF().get(inst1, inst2) * 10000.0) / 10000.0); } else if (inst1.getLabel().equals("DEPROT") && inst2.getLabel().equals("DEPROT")) { wr.writeln( "(" + inst1.getName() + "_DEPROTONATED, " + inst2.getName() + "_DEPROTONATED) " + Math.round(sys.getBinaryNF().get(inst1, inst2) * 10000.0) / 10000.0); } } } } } // Set<Vector<Instance>> keysNF = sys.getBinaryNF().keySet(); // for (Vector<Instance> key : keysNF){ // Instance key1 = key.get(0); // Instance key2 = key.get(1); // if (key1.getLabel().equals("PROT") && key2.getLabel().equals("PROT")){ // wr.writeln("("+key1.getName()+"_PROTONATED, "+key2.getName()+"_PROTONATED) // "+Math.round(sys.getBinaryNF().get(key1, key2)*10000.0)/10000.0); // }else if (key1.getLabel().equals("PROT") && key2.getLabel().equals("DEPROT")){ // wr.writeln("("+key1.getName()+"_PROTONATED, "+key2.getName()+"_DEPROTONATED) // "+Math.round(sys.getBinaryNF().get(key1, key2)*10000.0)/10000.0); // }else if (key1.getLabel().equals("DEPROT") && key2.getLabel().equals("PROT")){ // wr.writeln("("+key1.getName()+"_DEPROTONATED, "+key2.getName()+"_PROTONATED) // "+Math.round(sys.getBinaryNF().get(key1, key2)*10000.0)/10000.0); // }else{ // wr.writeln("("+key1.getName()+"_DEPROTONATED, "+key2.getName()+"_DEPROTONATED) // "+Math.round(sys.getBinaryNF().get(key1, key2)*10000.0)/10000.0); // } // } // unary for (Variable var : sys.getVars()) { for (Instance inst : var.getInstances()) { if (inst.getLabel().equals("PROT")) { wr.writeln( inst.getName() + "_PROTONATED " + Math.round(inst.getEnergyNF() * 10000.0) / 10000.0); } else if (inst.getLabel().equals("DEPROT")) { wr.writeln( inst.getName() + "_DEPROTONATED " + Math.round(inst.getEnergyNF() * 10000.0) / 10000.0); } else { wr.writeln( inst.toString() + "_OTHER " + Math.round(inst.getEnergyNF() * 10000.0) / 10000.0); } } } // constant wr.writeln( "Normalized constant energy: " + Math.round(sys.getConstantNF() * 10000.0) / 10000.0); sysBiGr = new BinaryGraph(sys, false, wr); } }
public void simplify() { Vector<Variable> toRemove = new Vector<Variable>(); Vector<Vector<Instance>> toRemoveFromBi = new Vector<Vector<Instance>>(); for (Variable v : residues) { // Instances within variable v Vector<Instance> vis = v.getInstances(); if (vis.size() == 1) { // if there is only one instance we must // (a) remove it toRemove.add(v); // (b) add its energy to the constant con += vis.get(0).getEnergy() * 0.5; for (Variable w : residues) { if (v.equals(w)) continue; // (c) add its interaction energy with other instances // either to the constant or to the unary energy // of the other instances Vector<Instance> wis = w.getInstances(); if (wis.size() == 1) { // if the other variable has only one instance then // we add the binary energy between the two instances // to the constant and we mark the other variable // for removal toRemove.add(w); con += bi.get(vis.get(0), wis.get(0)) * 0.5; Vector<Instance> temp = new Vector<Instance>(2); temp.add(0, vis.get(0)); temp.add(1, wis.get(0)); toRemoveFromBi.add(temp); } else { // if w has multiple instances then we add the // binary energy to the unary energy of the // instance of w for (Instance wi : wis) { wi.setEnergy(wi.getEnergy() + bi.get(vis.get(0), wi) * 0.5); Vector<Instance> temp = new Vector<Instance>(2); temp.add(0, vis.get(0)); temp.add(1, wi); toRemoveFromBi.add(temp); } } } } else { // if there are multiple instances of v then we look at other instances // to update the energy of v if needed for (Variable w : residues) { if (v.equals(w)) continue; Vector<Instance> wis = w.getInstances(); if (wis.size() == 1) { toRemove.add(w); for (Instance vi : vis) { vi.setEnergy(vi.getEnergy() + bi.get(vi, wis.get(0)) * 0.5); Vector<Instance> temp = new Vector<Instance>(2); temp.add(0, vi); temp.add(1, wis.get(0)); toRemoveFromBi.add(temp); } } else { // both v and w have multiple instances so we do nothing } } } } residues.removeAll(toRemove); bi.removeAll(toRemoveFromBi); }