2 Heat Capacity of RNA molecule
4 c Ivo Hofacker and Peter Stadler
8 calculates specific heat using C = - T d^2/dT^2 G(T)
18 #include "fold_vars.h"
21 #include "part_func.h"
22 #include "read_epars.h"
23 #include "RNAheat_cmdl.h"
26 static char rcsid[] = "$Id: RNAheat.c,v 1.12 2000/09/28 11:23:14 ivo Rel $";
29 #define GASCONST 1.98717 /* in [cal/K] */
32 PRIVATE float F[MAXWIDTH];
33 PRIVATE float ddiff(float f[], float h, int m);
34 PRIVATE void heat_capacity(char *string, float T_min, float T_max, float h, int m);
36 int main(int argc, char *argv[]){
37 struct RNAheat_args_info args_info;
38 char *string, *input_string, *ns_bases, *c, *ParamFile, *rec_sequence, *rec_id, **rec_rest, *orig_sequence;
39 int i, length, l, sym;
40 float T_min, T_max, h;
41 int mpoints, istty, noconv = 0;
42 unsigned int input_type;
43 unsigned int rec_type, read_opt;
45 string = ParamFile = ns_bases = NULL;
50 dangles = 2; /* dangles can be 0 (no dangles) or 2, default is 2 */
51 rec_type = read_opt = 0;
52 rec_id = rec_sequence = orig_sequence = NULL;
56 #############################################
57 # check the command line parameters
58 #############################################
60 if(RNAheat_cmdline_parser(argc, argv, &args_info) != 0) exit(1);
62 /* do not take special tetra loop energies into account */
63 if(args_info.noTetra_given) tetra_loop=0;
64 /* set dangle model */
65 if(args_info.dangles_given){
66 if((args_info.dangles_arg != 0) && (args_info.dangles_arg != 2))
67 warn_user("required dangle model not implemented, falling back to default dangles=2");
69 dangles = args_info.dangles_arg;
71 /* do not allow weak pairs */
72 if(args_info.noLP_given) noLonelyPairs = 1;
73 /* do not allow wobble pairs (GU) */
74 if(args_info.noGU_given) noGU = 1;
75 /* do not allow weak closing pairs (AU,GU) */
76 if(args_info.noClosingGU_given) no_closingGU = 1;
77 /* do not convert DNA nucleotide "T" to appropriate RNA "U" */
78 if(args_info.noconv_given) noconv = 1;
79 /* set energy model */
80 if(args_info.energyModel_given) energy_set = args_info.energyModel_arg;
81 /* take another energy parameter set */
82 if(args_info.paramFile_given) ParamFile = strdup(args_info.paramFile_arg);
83 /* Allow other pairs in addition to the usual AU,GC,and GU pairs */
84 if(args_info.nsp_given) ns_bases = strdup(args_info.nsp_arg);
86 if(args_info.Tmin_given) T_min = args_info.Tmin_arg;
88 if(args_info.Tmax_given) T_max = args_info.Tmax_arg;
90 if(args_info.stepsize_given) h = args_info.stepsize_arg;
92 if(args_info.ipoints_given){
93 mpoints = args_info.ipoints_arg;
94 if (mpoints < 1) mpoints = 1;
95 if (mpoints > 100) mpoints = 100;
98 /* free allocated memory of command line data structure */
99 RNAheat_cmdline_parser_free (&args_info);
102 #############################################
104 #############################################
106 if (ParamFile!=NULL) read_parameter_file(ParamFile);
108 if (ns_bases != NULL) {
109 nonstandards = space(33);
117 nonstandards[i++]=*c++;
118 nonstandards[i++]=*c;
119 if ((sym)&&(*c!=*(c-1))) {
120 nonstandards[i++]=*c;
121 nonstandards[i++]=*(c-1);
128 istty = isatty(fileno(stdout))&&isatty(fileno(stdin));
130 read_opt |= VRNA_INPUT_NO_REST;
132 print_tty_input_seq();
133 read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES;
137 #############################################
138 # main loop: continue until end of file
139 #############################################
142 !((rec_type = read_record(&rec_id, &rec_sequence, &rec_rest, read_opt))
143 & (VRNA_INPUT_ERROR | VRNA_INPUT_QUIT))){
145 ########################################################
146 # init everything according to the data we've read
147 ########################################################
149 if(rec_id && !istty) printf("%s\n", rec_id);
151 length = (int)strlen(rec_sequence);
153 /* convert DNA alphabet to RNA if not explicitely switched off */
154 if(!noconv) str_DNA2RNA(rec_sequence);
155 /* store case-unmodified sequence */
156 orig_sequence = strdup(rec_sequence);
157 /* convert sequence to uppercase letters only */
158 str_uppercase(rec_sequence);
160 if(istty) printf("length = %d\n", length);
162 ########################################################
163 # done with 'stdin' handling
164 ########################################################
167 heat_capacity(rec_sequence, T_min, T_max, h, mpoints);
168 (void) fflush(stdout);
171 if(rec_id) free(rec_id);
174 rec_id = rec_sequence = orig_sequence = NULL;
176 /* print user help for the next round if we get input from tty */
178 if(istty) print_tty_input_seq();
183 PRIVATE void heat_capacity(char *string, float T_min, float T_max,
188 float hc, kT, min_en;
190 length = (int) strlen(string);
194 temperature = T_min -m*h;
195 /* initialize_fold(length); <- obsolete */
196 structure = (char *) space((unsigned) length+1);
197 min_en = fold(string, structure);
198 free(structure); free_arrays();
199 kT = (temperature+K0)*GASCONST/1000; /* in kcal */
200 pf_scale = exp(-(1.07*min_en)/kT/length );
201 /* init_pf_fold(length); <- obsolete */
202 pf_paramT *pf_parameters = NULL;
204 set_model_details(&md);
206 for (i=0; i<2*m+1; i++) {
207 if(pf_parameters) free(pf_parameters);
208 pf_parameters = get_boltzmann_factors(temperature, 1.0, md, pf_scale);
209 F[i] = pf_fold_par(string, NULL, pf_parameters, 0, 0, 0); /* T_min -2h */
211 kT = (temperature+K0)*GASCONST/1000;
212 pf_scale=exp(-(F[i]/length +h*0.00727)/kT); /* try to extrapolate F */
213 update_pf_params(length);
215 while (temperature <= (T_max+m*h+h)) {
217 hc = - ddiff(F,h,m)* (temperature +K0 - m*h -h);
218 printf("%g %g\n", (temperature-m*h-h), hc);
220 for (i=0; i<2*m; i++)
223 F[2*m] = pf_fold_par(string, NULL, pf_parameters, 0, 0, 0);
224 /* printf("%g\n", F[2*m]);*/
226 kT = (temperature+K0)*GASCONST/1000;
227 pf_scale=exp(-(F[i]/length +h*0.00727)/kT);
228 if(pf_parameters) free(pf_parameters);
229 pf_parameters = get_boltzmann_factors(temperature, 1.0, md, pf_scale);
230 update_pf_params(length);
235 /* ------------------------------------------------------------------------- */
237 PRIVATE float ddiff(float f[], float h, int m)
242 A = (float)(m*(m+1)*(2*m+1)/3 ); /* 2*sum(x^2) */
243 B = (float)(m*(m+1)*(2*m+1) ) * (float)(3*m*m+3*m-1) /15.; /* 2*sum(x^4) */
246 for (i=0; i<2*m+1; i++)
247 fp += f[i]*( A - (float) ( (2*m+1)*(i-m)*(i-m)) );
249 fp /= ( ( A*A - B*( (float)(2*m+1) ) )*h*h/2. );