Skip to content

Commit

Permalink
Prelminary fix for logging bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfaeder committed May 15, 2024
1 parent 31eef54 commit a93c015
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 26 deletions.
55 changes: 30 additions & 25 deletions src/NFinput/NFinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,33 +1051,38 @@ string NFinput::initStartSpecies(
// AS2023 - start initial state block
string logstr = " \"initialState\": {\n";
logstr += " \"molecule_array\": [\n";
// AS2023 - to add compression we make the full molecule type
// vector first
int molec_size = *max_element(mgids.begin(), mgids.end());
molec_size+=1;
vector <int> molec_vec;
for(unsigned int isi=0; isi<molec_size; isi++) {
molec_vec.push_back(-1);
}
for(unsigned int img=0; img<mgids.size(); img++) {
molec_vec[mgids[img]] = mids[img];
}
// AS2023 - now we use it to compress the initial state vector
int last_val = molec_vec[0];
int val_ctr = 1;
for(unsigned int ici=1; ici<molec_vec.size(); ici++) {
if (molec_vec[ici]!=last_val) {
logstr += " [" + to_string(last_val) + "," + to_string(val_ctr) + "],\n";
last_val = molec_vec[ici];
val_ctr = 1;
} else {
val_ctr += 1;
// cout << "number of molecules: " << mgids.size() << endl;
if (mgids.size()>0){
// AS2023 - to add compression we make the full molecule type
// vector first
int molec_size = *max_element(mgids.begin(), mgids.end());
molec_size+=1;
vector <int> molec_vec;
for(unsigned int isi=0; isi<molec_size; isi++) {
molec_vec.push_back(-1);
}
for(unsigned int img=0; img<mgids.size(); img++) {
molec_vec[mgids[img]] = mids[img];
}
// AS2023 - now we use it to compress the initial state vector
int last_val = molec_vec[0];
int val_ctr = 1;
for(unsigned int ici=1; ici<molec_vec.size(); ici++) {
if (molec_vec[ici]!=last_val) {
logstr += " [" + to_string(last_val) + "," + to_string(val_ctr) + "],\n";
last_val = molec_vec[ici];
val_ctr = 1;
} else {
val_ctr += 1;
}
}
logstr += " [" + to_string(last_val) + "," + to_string(val_ctr) + "]\n";
// logstr += " [" + to_string(last_val) + "," + to_string(val_ctr) + "],\n";
// // AS 2023
// logstr.erase(logstr.end()-2, logstr.end());
}
logstr += " [" + to_string(last_val) + "," + to_string(val_ctr) + "],\n";
// AS 2023
logstr.erase(logstr.end()-2, logstr.end());
logstr += "\n ],\n";
logstr += " ],\n";

// AS2023
logstr += " \"ops\": [\n ";
for(int k=0;k<operations.size();k++) {
Expand Down
2 changes: 1 addition & 1 deletion src/NFsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ int main(int argc, char *argv[])
// turned off for the general release code.
//if (!schedulerInterpreter(&argc, &argv)) return 0;

string versionNumber = "1.14.1";
string versionNumber = "1.14.2";
cout<<"starting NFsim v"+versionNumber+"..."<<endl<<endl;
clock_t start,finish;
double time;
Expand Down
80 changes: 80 additions & 0 deletions test/Issue37/issue37.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by BioNetGen 2.9.0 -->
<sbml xmlns="http://www.sbml.org/sbml/level3" level="3" version="1">
<model id="uhohnfsim">
<ListOfParameters>
<Parameter id="_rateLaw1" type="Constant" value="10" expr="10"/>
<Parameter id="_rateLaw2" type="Constant" value="1" expr="1"/>
</ListOfParameters>
<ListOfMoleculeTypes>
<MoleculeType id="A"/>
</ListOfMoleculeTypes>
<ListOfCompartments>
</ListOfCompartments>
<ListOfSpecies>
<Species id="S1" concentration="10" name="A()">
<ListOfMolecules>
<Molecule id="S1_M1" name="A"/>
</ListOfMolecules>
</Species>
</ListOfSpecies>
<ListOfReactionRules>
<ReactionRule id="RR1" name="_R1" symmetry_factor="1">
<ListOfReactantPatterns>
</ListOfReactantPatterns>
<ListOfProductPatterns>
<ProductPattern id="RR1_PP1">
<ListOfMolecules>
<Molecule id="RR1_PP1_M1" name="A"/>
</ListOfMolecules>
</ProductPattern>
</ListOfProductPatterns>
<RateLaw id="RR1_RateLaw" type="Ele" totalrate="0">
<ListOfRateConstants>
<RateConstant value="_rateLaw1"/>
</ListOfRateConstants>
</RateLaw>
<Map>
</Map>
<ListOfOperations>
<Add id="RR1_PP1_M1"/>
</ListOfOperations>
</ReactionRule>
<ReactionRule id="RR2" name="_reverse__R1" symmetry_factor="1">
<ListOfReactantPatterns>
<ReactantPattern id="RR2_RP1">
<ListOfMolecules>
<Molecule id="RR2_RP1_M1" name="A"/>
</ListOfMolecules>
</ReactantPattern>
</ListOfReactantPatterns>
<ListOfProductPatterns>
</ListOfProductPatterns>
<RateLaw id="RR2_RateLaw" type="Ele" totalrate="0">
<ListOfRateConstants>
<RateConstant value="_rateLaw2"/>
</ListOfRateConstants>
</RateLaw>
<Map>
<MapItem sourceID="RR2_RP1_M1"/>
</Map>
<ListOfOperations>
<Delete id="RR2_RP1" DeleteMolecules="0"/>
</ListOfOperations>
</ReactionRule>
</ListOfReactionRules>
<ListOfObservables>
<Observable id="O1" name="A" type="Molecules">
<ListOfPatterns>
<Pattern id="O1_P1">
<ListOfMolecules>
<Molecule id="O1_P1_M1" name="A"/>
</ListOfMolecules>
</Pattern>
</ListOfPatterns>
</Observable>
</ListOfObservables>
<ListOfFunctions>
</ListOfFunctions>
</model>
</sbml>
18 changes: 18 additions & 0 deletions test/Issue37/issue37_test2.bngl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
begin model

begin species
A() 100
B() 0
end species

begin observables
Molecules A A()
end observables

begin reaction rules
0 <-> A() 10,1
end reaction rules

end model

simulate({method=>"nf",t_end=>100,n_steps=>100})
86 changes: 86 additions & 0 deletions test/Issue37/issue37_test2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by BioNetGen 2.9.1 -->
<sbml xmlns="http://www.sbml.org/sbml/level3" level="3" version="1">
<model id="issue37_test2">
<ListOfParameters>
<Parameter id="_rateLaw1" type="Constant" value="10" expr="10"/>
<Parameter id="_rateLaw2" type="Constant" value="1" expr="1"/>
</ListOfParameters>
<ListOfMoleculeTypes>
<MoleculeType id="A"/>
<MoleculeType id="B"/>
</ListOfMoleculeTypes>
<ListOfCompartments>
</ListOfCompartments>
<ListOfSpecies>
<Species id="S1" concentration="100" name="A()">
<ListOfMolecules>
<Molecule id="S1_M1" name="A"/>
</ListOfMolecules>
</Species>
<Species id="S2" concentration="0" name="B()">
<ListOfMolecules>
<Molecule id="S2_M1" name="B"/>
</ListOfMolecules>
</Species>
</ListOfSpecies>
<ListOfReactionRules>
<ReactionRule id="RR1" name="_R1" symmetry_factor="1">
<ListOfReactantPatterns>
</ListOfReactantPatterns>
<ListOfProductPatterns>
<ProductPattern id="RR1_PP1">
<ListOfMolecules>
<Molecule id="RR1_PP1_M1" name="A"/>
</ListOfMolecules>
</ProductPattern>
</ListOfProductPatterns>
<RateLaw id="RR1_RateLaw" type="Ele" totalrate="0">
<ListOfRateConstants>
<RateConstant value="_rateLaw1"/>
</ListOfRateConstants>
</RateLaw>
<Map>
</Map>
<ListOfOperations>
<Add id="RR1_PP1_M1"/>
</ListOfOperations>
</ReactionRule>
<ReactionRule id="RR2" name="_reverse__R1" symmetry_factor="1">
<ListOfReactantPatterns>
<ReactantPattern id="RR2_RP1">
<ListOfMolecules>
<Molecule id="RR2_RP1_M1" name="A"/>
</ListOfMolecules>
</ReactantPattern>
</ListOfReactantPatterns>
<ListOfProductPatterns>
</ListOfProductPatterns>
<RateLaw id="RR2_RateLaw" type="Ele" totalrate="0">
<ListOfRateConstants>
<RateConstant value="_rateLaw2"/>
</ListOfRateConstants>
</RateLaw>
<Map>
<MapItem sourceID="RR2_RP1_M1"/>
</Map>
<ListOfOperations>
<Delete id="RR2_RP1" DeleteMolecules="0"/>
</ListOfOperations>
</ReactionRule>
</ListOfReactionRules>
<ListOfObservables>
<Observable id="O1" name="A" type="Molecules">
<ListOfPatterns>
<Pattern id="O1_P1">
<ListOfMolecules>
<Molecule id="O1_P1_M1" name="A"/>
</ListOfMolecules>
</Pattern>
</ListOfPatterns>
</Observable>
</ListOfObservables>
<ListOfFunctions>
</ListOfFunctions>
</model>
</sbml>

0 comments on commit a93c015

Please sign in to comment.