Package com.mockturtlesolutions.snifflib.datatypes

Examples of com.mockturtlesolutions.snifflib.datatypes.DblMatrix


    return(this.N_titrant);
  }
 
  public HashMap ionicStr()
  {
    DblMatrix pH = DblMatrix.span(2,12,25);
    HashMap out = this.ionicStr(pH,false,null);
    return(out);
  }
View Full Code Here


  {
       

    pH.vec();//Make pH a column vector.
    pH.show("pH");
    DblMatrix H = DblMatrix.pow(10,pH.times(-1));
   
    //Set Names = this.bufferMap.keySet();
   
    String[] Names = this.bufferPredictor.getComponents();
    int num_bufs = Names.length; //Number of buffers in this solution.
    HashMap OUT = new HashMap();
   
    // DblMatrix[] OUT;
//     if (do_partial)
//     {
//       OUT = new DblMatrix[num_bufs];
//       for (int j=0;j<num_bufs;j++)
//       {
//         OUT[j] = new DblMatrix(H.getN());
//       }
//     }
//     else
//     {
//       OUT = new DblMatrix[1];
//       OUT[0] = new DblMatrix(H.getN());
//     }
//    
   
    //Iterator iter = Names.iterator();
    String buffname;
    //BufferDOM buffer;
    ComplexBufferComponent buffer;
    DblMatrix C;
    DblMatrix IonicStr=new DblMatrix(H.getN());
    HashMap Coefs;
    DblMatrix[] KKa;
    DblMatrix[] KKb;
    DblMatrix[] SSaltType;
    DblMatrix Kw;
    BufferPredictor complex;
   
   
   
    //Calculate ion product constant of water Kw.
    //buffer = (BufferDOM)this.bufferMap.get("com.mockturtlesolutions.water");
    buffer = this.bufferPredictor.getComponent("com.mockturtlesolutions.water");
    if (buffer == null)
    {
      throw new IllegalArgumentException("Water must be a component of the solution.");
    }
   
    //Coefs = getAverageKa(buffer);
    Coefs = this.bufferPredictor.getEstimatedKa("com.mockturtlesolutions.water");
   
    //C = (DblMatrix)this.concentrationMap.get("com.mockturtlesolutions.water");
    C = this.bufferPredictor.getEstimatedConcentration("com.mockturtlesolutions.water");
    KKa = (DblMatrix[])Coefs.get("Ka");
    Kw = KKa[0].times(C);
   
   
   
    ///
   
    //while (iter.hasNext()) //For each named buffer in the solution...
    for (int j=0;j<Names.length;j++)
    { 
      IonicStr=new DblMatrix(H.getN());
      System.out.println("Right Here");
      //buffname = (String)iter.next();
     
      buffname = Names[j];
      buffer = this.bufferPredictor.getComponent(buffname);
     
      //buffer = (BufferDOM)this.bufferMap.get(buffname);
      //C = (DblMatrix)this.concentrationMap.get(buffname);
      C = this.bufferPredictor.getEstimatedConcentration(buffname);
      complex = buffer.getSmooth();
     
      if (complex != null) //This is a COMPLEX buffer.
      {
   
        System.out.println("This is a complex buffer!:");
        // if (do_partial)
//         {
//        
//            OUT.put(buffname,C*feval(SOL(i).Func.EvalFun,SOL(i).Func.Smooth,pH,25,SOL(i).Contains)); 
//          }
//         else
//         {   
//            OUT = OUT + SOL(i).Conc*feval(SOL(i).Func.EvalFun,SOL(i).Func.Smooth,pH,25,SOL(i).Contains); 
//         }
      }
      else
      {
        //Coefs = getAverageKa(buffer);
       
        Coefs = this.bufferPredictor.getEstimatedKa(buffname);
       
 
              KKa = (DblMatrix[])Coefs.get("Ka");
              KKb = (DblMatrix[])Coefs.get("Kb");
        SSaltType = (DblMatrix[])Coefs.get("SaltType");
       
        if (buffname.endsWith(".water"))
        {

          
          IonicStr = Kw.divideBy(H).plus(H);
           
        }
        else
        {
       

          int num_pka,num_pkb,N,n;
          DblMatrix Ka;
         
          DblMatrix Numerator;
          DblMatrix Denominator;
          DblMatrix IonicStrtemp;
          for (int k=0;k<KKa.length;k++) //For each ion...
         
            Numerator = new DblMatrix(H.getN());
                  Denominator = new DblMatrix(H.getN());
           
            num_pka = KKa[k].getN();
            num_pkb = KKb[k].getN();
           
            if ((num_pka == 0) && (num_pkb ==0))
            {
              if (SSaltType[k].getN() == 1)
              {
                //System.out.println("Electrolyte"+k);
                //SSaltType[k].show("SaltType[k]");
                IonicStrtemp = SSaltType[k].pow(2);
              }
              else
              {
                if (SSaltType[k].getN() > 1)
                {
                  throw new RuntimeException("SaltType of an electrolyte can not consist of more than one integer value.")
                }
                else
                {
                  System.out.println("Inert thing"+k);
                  //Would be something completely inert like glucose.
                  IonicStrtemp =  new DblMatrix(0.0);
                }
              }
            } 
            else
            {
              N = num_pka + num_pkb;
              n = num_pka;
              Ka = KKa[k];
              Ka.show("Ka");
              if (num_pkb > 0)
              {
                DblMatrix transKb = Kw.divideBy(KKb[k]);
                Ka = Ka.concat(transKb,2);
              }
              DblSort Sort = new DblSort(Ka,2);
              Sort.sort();
              Ka = Sort.getSorted();


              //Calculate numerator
              DblMatrix cumProdKa = Ka.cumProd(1);
              cumProdKa = cumProdKa.fliplr();
              DblMatrix temp;

              Ka.show("Final Ka");
              for (int i=1;i<=N;i++)
              {
                temp = H.pow(i-1).times(cumProdKa.getDoubleAt(i-1));
                Denominator = Denominator.plus(temp);
                temp = temp.times(n+1-i);
                temp = temp.times(n+1-i);
                Numerator = Numerator.plus(temp);
              }
              //Denominator gets one more term than numerator...
              Denominator = Denominator.plus(H.pow(N))

              Denominator.show("Denominator");
              IonicStrtemp = Numerator.divideBy(Denominator);
            }
            IonicStr = IonicStr.plus(C.times(IonicStrtemp));

          }
        }
      }
      IonicStr = IonicStr.times(0.5);
      
      IonicStr.show(buffname);
     
     
      //Enter latest IonicStr calculation into the results for output.
      if (do_partial)
      {
        OUT.put(buffname,IonicStr)
      }
     
      if (OUT.containsKey("total"))
      {
       
        OUT.put("total",IonicStr.plus((DblMatrix)OUT.get("total")));
      }
      else
      {
        OUT.put("total",IonicStr);
      }
     
     
    }
   
    //Put in the contribution to ionic strength from the titrant!
    //Enter latest IonicStr calculation into the results for output.
   
    //DefaultCbAlgorithm CbAlg = new DefaultCbAlgorithm(this.bufferMap,this.concentrationMap);
   
    DefaultCbAlgorithm CbAlg = new DefaultCbAlgorithm(this.bufferPredictor);
   
    HashMap titrant = CbAlg.Cb(pH);
    DblMatrix Cb = (DblMatrix)titrant.get("total");
    IonicStr =DblMatrix.abs(Cb).times(N_titrant);
    //Note that this is really N_titrant^(2)*Cb/N_titrant  simplified!! 
   
    IonicStr = IonicStr.times(0.5);
    if (do_partial)
View Full Code Here

    Vector pKaSet = new Vector();
    int ionStart=0;
    int ionStop=0;
    String ion;
    boolean readingIon=false;
    DblMatrix val;
    int k=0;
    while (k<pKa.length())
    {
      if (pKa.charAt(k)=='[')
      {
        if (readingIon)
        {
          throw new RuntimeException("Encountered extra '[' in buffer coefficients.")
        }
        readingIon = true;
        ionStart = k;
       
      }
      else
      {
        if (pKa.charAt(k)==']')
        {
          if (!readingIon)
          {
            throw new RuntimeException("Encountered extra ']' in buffer coefficients.")
          }
          ionStop = k+1;
          ion = pKa.substring(ionStart,ionStop);
          pKaSet.add(new DblMatrix(ion));
         
          readingIon = false;
        }
      }
      k++;
View Full Code Here

    Vector pKaSet = new Vector();
    int ionStart=0;
    int ionStop=0;
    String ion;
    boolean readingIon=false;
    DblMatrix val;
    int k=0;
    while (k<pKa.length())
    {
      if (pKa.charAt(k)=='[')
      {
        if (readingIon)
        {
          throw new RuntimeException("Encountered extra '[' in buffer coefficients.")
        }
        readingIon = true;
        ionStart = k;
       
      }
      else
      {
        if (pKa.charAt(k)==']')
        {
          if (!readingIon)
          {
            throw new RuntimeException("Encountered extra ']' in buffer coefficients.")
          }
          ionStop = k+1;
          ion = pKa.substring(ionStart,ionStop);
          pKaSet.add(new DblMatrix(ion));
         
          readingIon = false;
        }
      }
      k++;
View Full Code Here

    Vector pKaSet = new Vector();
    int ionStart=0;
    int ionStop=0;
    String ion;
    boolean readingIon=false;
    DblMatrix val;
    int k=0;
    while (k<pKa.length())
    {
      if (pKa.charAt(k)=='[')
      {
        if (readingIon)
        {
          throw new RuntimeException("Encountered extra '[' in buffer coefficients.")
        }
        readingIon = true;
        ionStart = k;
       
      }
      else
      {
        if (pKa.charAt(k)==']')
        {
          if (!readingIon)
          {
            throw new RuntimeException("Encountered extra ']' in buffer coefficients.")
          }
          ionStop = k+1;
          ion = pKa.substring(ionStart,ionStop);
          pKaSet.add(new DblMatrix(ion));
         
          readingIon = false;
        }
      }
      k++;
View Full Code Here

    Vector pKaSet = new Vector();
    int ionStart=0;
    int ionStop=0;
    String ion;
    boolean readingIon=false;
    DblMatrix val;
    int k=0;
    while (k<pKa.length())
    {
      if (pKa.charAt(k)=='[')
      {
        if (readingIon)
        {
          throw new RuntimeException("Encountered extra '[' in buffer coefficients.")
        }
        readingIon = true;
        ionStart = k;
       
      }
      else
      {
        if (pKa.charAt(k)==']')
        {
          if (!readingIon)
          {
            throw new RuntimeException("Encountered extra ']' in buffer coefficients.")
          }
          ionStop = k+1;
          ion = pKa.substring(ionStart,ionStop);
          pKaSet.add(new DblMatrix(ion));
         
          readingIon = false;
        }
      }
      k++;
View Full Code Here

   
    String[] names = this.summaryBuffer.getComponents();
   
   
    Iterator iter;
    DblMatrix concentration;
    String buffer;
    //Remove all the buffers currently stored in this buffer solution.
    //Saving their concentrations to the HashMap oldConcMap.
    HashSet toRemove = new HashSet();
    //System.out.println("Setting repository for BufferSolution a"+names.size());
View Full Code Here

   
   
    //Set cnts = contents.keySet();
    //Iterator iter = cnts.iterator();
   
    DblMatrix concentration;
    String buffer;
   
   
    String[] comps = A.getComponents();
   
    //while (iter.hasNext())
    for (int c=0;c<comps.length;c++)
    {
      //buffer = (String)iter.next();
      buffer = comps[c];
      //concentration = (DblMatrix)contents.get(buffer);
      concentration = A.getConcentration(buffer);
      newSol.add(buffer,concentration);
    }
   
   
    //contents = B.getContents();
    //cnts = contents.keySet();
    //iter = cnts.iterator();
    comps = B.getComponents();
    //while (iter.hasNext())
    for (int c=0;c<comps.length;c++)
    {
      //buffer = (String)iter.next();
      buffer = comps[c];
      concentration = B.getConcentration(buffer);
      newSol.increase(buffer,concentration.getDoubleAt(0).doubleValue());
   
    }
   
    return(newSol);
  }
View Full Code Here

    //HashMap contents = A.getContents();
    //Set cnts = contents.keySet();
    //Iterator iter = cnts.iterator();
   
    String[] comps = A.getComponents();
    DblMatrix concentration;
    String buffer;
   
   
    for (int c=0;c<comps.length;c++)
    //while (iter.hasNext())
    {
      //buffer = (String)iter.next();
      buffer = comps[c];
      concentration = A.getConcentration(buffer);
      newSol.add(buffer,concentration);
    }
   
   
    comps = B.getComponents();
    //contents = B.getContents();
    //cnts = contents.keySet();
    //iter = cnts.iterator();
   
    //while (iter.hasNext())
    for (int c=0;c<comps.length;c++)
    {
      //buffer = (String)iter.next();
      buffer = comps[c];
      //concentration = (DblMatrix)contents.get(buffer);
      concentration = B.getConcentration(buffer);
      newSol.decrease(buffer,concentration.getDoubleAt(0).doubleValue());
   
    }
   
    return(newSol);
   
View Full Code Here

   
    String[] names = A.getComponents();
    //Set cnts = contents.keySet();
    //Iterator iter = cnts.iterator();
   
    DblMatrix concentration;
    String buffer;
   
    double facA = a/(a+b);
    double facB = b/(a+b);
   
   
    for (int c=0;c<names.length;c++)
    {
      // //buffer = (String)iter.next();
       buffer = names[c];
//       //concentration = (DblMatrix)contents.get(buffer);
//       concentration = A.getConcentration(buffer);
//       //BufferStorage storage = A.getBufferStorage(buffer);
//       System.out.println("Increasing buffer:"+buffer);
//       //System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ");
//       newSol.increase(buffer,(concentration.times(facA)).getDoubleAt(0).doubleValue());
//       //newSol.increase(storage,(concentration.getDoubleAt(0).doubleValue())*facA);
      concentration = A.getConcentration(buffer);
      newSol.setConcentration(buffer,concentration.times(facA));
   
    }
   
    cpu2 = System.nanoTime();
    //System.out.println("M2="+(cpu2-cpu));
    cpu = cpu2;
    //System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ");
    //contents = B.getContents();
    //cnts = contents.keySet();
    //iter = cnts.iterator();
   
    names = B.getComponents();
    for (int c=0;c<names.length;c++)
    {
   
      buffer = names[c];
      //buffer = (String)iter.next();
      //concentration = (DblMatrix)contents.get(buffer);
      concentration = B.getConcentration(buffer);
      //BufferStorage storage = B.getBufferStorage(buffer);
      //System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ");
      newSol.increase(buffer,(concentration.times(facB).getDoubleAt(0).doubleValue()));
    }
    cpu2 = System.nanoTime();
    //System.out.println("M3="+(cpu2-cpu));
    cpu = cpu2;
    //System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ");
View Full Code Here

TOP

Related Classes of com.mockturtlesolutions.snifflib.datatypes.DblMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.