Exemplo n.º 1
0
  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);
  }
Exemplo n.º 2
0
  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);
  }