//
newcomp.setName(bs.getNickname());
//All top-level components should get assigned an initial concentration of 1.0. This
//jibes with the convention for complex buffers ("full strength" e.g. 1X ).
newcomp.setConcentration(new DblMatrix(1.0));
out.addComponent(bs.getNickname(),newcomp);
Vector exps = bs.getExperimentNames();
//Do some preliminary checking of the top level...
boolean CONTAINED_SPECIFIED_AT_LEAST_ONCE = false;
boolean COEFFICIENTS_SPECIFIED_AT_LEAST_ONCE = false;
for (int i=0;i<exps.size();i++)
{
String exp = (String)exps.get(i);
//System.out.println("Looking at exp:"+exp);
if (CONTAINED_SPECIFIED_AT_LEAST_ONCE == false)
{
Vector csubs = bs.getContainedSubsampleIDs(exp);
//System.out.println("Looking at subs:"+csubs.size());
if (csubs.size() > 0) //bs has contained buffers.
{
CONTAINED_SPECIFIED_AT_LEAST_ONCE = true;
}
}
if (COEFFICIENTS_SPECIFIED_AT_LEAST_ONCE == false)
{
Vector subsamples = bs.getBufferCoefficientsSubsampleIDs(exp);
//System.out.println("Looking at bsubs:"+subsamples.size());
if (subsamples.size() > 0)
{
COEFFICIENTS_SPECIFIED_AT_LEAST_ONCE = true;
}
}
}
if (COEFFICIENTS_SPECIFIED_AT_LEAST_ONCE && CONTAINED_SPECIFIED_AT_LEAST_ONCE)
{
throw new RuntimeException("Buffer support can not have both contained buffers and dissociation constants specified. Please fix data.");
}
if (COEFFICIENTS_SPECIFIED_AT_LEAST_ONCE)
{
for (int i=0;i<exps.size();i++)
{
String exp = (String)exps.get(i);
Vector subsamples = bs.getBufferCoefficientsSubsampleIDs(exp);
for (int j=0;j<subsamples.size();j++) //There are buffer coefficients specified (e.g. as for a simple buffer like Malic acid)
{
HashMap avgpKa = AbstractSMPBuffer.getAveragepKa(bs);//This HashMap contains keys for pKa,pKb and SaltType
//The fields are DblMatrix[].
// Set keys = avgpKa.keySet();
// Iterator iter = keys.iterator();
// while (iter.hasNext())
// {
// System.out.println("KEY:"+iter.next());
// }
ComplexBufferComponent comp = out.getComponent(out.getName());
if (comp == null)
{
throw new RuntimeException("The component "+out.getName()+" is null.");
}
DblMatrix[] tmp = (DblMatrix[])avgpKa.get("SaltType");
//System.out.println("Lenght of tmp:"+tmp.length);
if (tmp == null)
{
comp.setSaltType(null);
}
else
{
comp.setSaltType(tmp);
}
comp.setpKa((DblMatrix[])avgpKa.get("pKa"));
comp.setpKb((DblMatrix[])avgpKa.get("pKb"));
}
}
}
if (CONTAINED_SPECIFIED_AT_LEAST_ONCE)
{
for (int i=0;i<exps.size();i++)
{
String exp = (String)exps.get(i);
Vector csubs = bs.getContainedSubsampleIDs(exp);
for (int j=0;j<csubs.size();j++)
{
String ssid = (String)csubs.get(j);
Vector obsnums = bs.getContainedObservationNumbers(exp,ssid);
for (int k=0;k<obsnums.size();k++)
{
String obs = (String)obsnums.get(j);
String buffername = bs.getContainedNickname(exp,ssid,obs);
String conc = bs.getContainedConcentration(exp,ssid,obs);
BufferStorage cont_buff = (bs.getConnection()).getBuffer(repos,buffername);
//THIS RECURSIVE CALL LEADS TO "FORWARDING" OF ANY SHARED CONTAINED COMPONENTS
//WITHIN THE CONTAINED COMPLEX COMPONENTS OF THIS BUFFER.
//
//FOR EXAMPLE SUPPOSE THIS BUFFER CONTAINS BOTH LEMON JUICE AND CITRIC ACID
//LEMON JUICE CONTAINS CITRIC ACID BUT THE PKA ARE ESTIMATED
//DIFFERENT VALUES THAN FOR CITRIC ACID AS A PURE SOLUTION. THE END VALUE FOR
//CITRIC ACID IN THE SOLUTION WILL BE THE WEIGHTED AVERAGE OF ALL PKA/PKB
//WHERE THE WEIGHTS ARE THE MOLAR CONCENTRATION OF EACH CONTRIBUTING SOURCE
//COMPONENT IN THE FINAL SOLUTION. SUPPOSE LEMON JUICE HAS 30mM CITRIC ACID AND
//THE SOLUTION BEING CONSTRUCTED HAS 20mM PURE CITRIC ACID ALSO 0.5X LEMON JUICE
//BEING ADDED. THEN THE PKA FOR CITRIC ACID ARE CALCULATED AS
//
// 15*(PKA_LEMONJUICE) + 20*(PKA_PURECITRIC)/(35)
//NOTE THAT THE FINAL CONCENTRATION OF CITRIC ACID WILL BE SAVED AS 35 MM AS WELL.
//
AbstractSMPBuffer.addToComplexBuffer(repos,out,cont_buff,new DblMatrix(conc),true);
}
}
}
}