aboutsummaryrefslogtreecommitdiff
blob: 911bc4dec327f65cc974f88ed36ca524fd6b87cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
diff -urN amber11.orig/AmberTools/src/configure amber11/AmberTools/src/configure
--- amber11.orig/AmberTools/src/configure	2011-04-14 15:30:55.000000000 +0300
+++ amber11/AmberTools/src/configure	2011-10-25 15:01:28.222288537 +0300
@@ -650,7 +650,7 @@
     if [ "$cuda" = 'yes' -o "$cuda_SPSP" = 'yes' -o "$cuda_DPDP" = 'yes' ]; then
       pmemd_cu_includes='-I$(CUDA_HOME)/include -IB40C -IB40C/KernelCommon'
       pmemd_cu_defines='-DCUDA'
-      pmemd_cu_libs='-L$(CUDA_HOME)/lib64 -L$(CUDA_HOME)/lib -lcufft -lcudart ./cuda/cuda.a'
+      pmemd_cu_libs='-L$(CUDA_HOME)/lib64 -L$(CUDA_HOME)/lib -lcurand -lcufft -lcudart ./cuda/cuda.a'
       if [ "$optimise" = 'no' ]; then
         nvcc='$(CUDA_HOME)/bin/nvcc -use_fast_math -O0 -gencode arch=compute_13,code=sm_13 -gencode arch=compute_20,code=sm_20'
       else
@@ -909,7 +909,7 @@
 
         pmemd_cu_includes='-I$(CUDA_HOME)/include -IB40C -IB40C/KernelCommon'
         pmemd_cu_defines='-DCUDA'
-        pmemd_cu_libs='-L$(CUDA_HOME)/lib64 -L$(CUDA_HOME)/lib -lcufft -lcudart ./cuda/cuda.a'
+        pmemd_cu_libs='-L$(CUDA_HOME)/lib64 -L$(CUDA_HOME)/lib -lcurand -lcufft -lcudart ./cuda/cuda.a'
         if [ "$optimise" = 'yes' ]; then
             nvcc='$(CUDA_HOME)/bin/nvcc -use_fast_math -O3 -gencode arch=compute_13,code=sm_13 -gencode arch=compute_20,code=sm_20'
         else
@@ -2111,21 +2111,21 @@
     echo "Change to \$AMBERHOME/src/ and type 'make clean' followed by"
     echo "'make parallel_win'."
   elif [ "$cuda" = 'yes' -o "$cuda_SPSP" = 'yes' -o "$cuda_DPDP" = 'yes' ]; then
-    echo "The next step is to cd to ../../src and type 'make install'"
+    echo "The next step is to cd to ../../src and type 'make $installtype'"
   else
     echo "If you have amber11, the most common next step is to "
-    echo "'cd ../../src; make clean; make install'.  See the Users' Manual"
+    echo "'cd ../../src; make clean; make $installtype'.  See the Users' Manual"
     echo "for information on building a parallel version of AmberTools"
   fi
 elif [ "$cuda" = 'yes' -o "$cuda_SPSP" = 'yes' -o "$cuda_DPDP" = 'yes' ]; then
-  echo "The next step is to cd to ../../src and type 'make install'"
+  echo "The next step is to cd to ../../src and type 'make $installtype'"
 elif [ "$windows" = 'yes' ]; then
   echo "The next step is to switch to a dos shell with ifort enabled."
   echo "Change to \$AMBERHOME/src/ and type 'make serial_win'."
 elif [ "$openmp" = 'yes' ]; then
   echo "The next step is to type 'make nabonly'"
 else
-  echo "The next step is to type 'make install'"
+  echo "The next step is to type 'make $installtype'"
 fi
 echo " "
 
@@ -2149,7 +2149,7 @@
    echo " NOTE: after installing AmberTools, if you want to compile"
    echo "       Amber11 using AmberTools 1.5, you must run the "
    echo "       AT15_Amber11.py script first, e.g.:"
-   echo "       cd $AMBERHOME; ./AT15_Amber11.py; make $installtype"
+   echo "       cd $AMBERHOME; ./AT15_Amber11.py; cd src; make $installtype"
    echo "       (See the Amber11 Users' Manual for full instructions,"
    echo "       and be sure to have a backup, since the AT15_Amber11.py"
    echo "       script will modify your Amber11 files.)"
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Center.cpp amber11/AmberTools/src/cpptraj/src/Action_Center.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Center.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Center.cpp	2011-10-25 15:01:28.108288642 +0300
@@ -72,7 +72,7 @@
 // else
 //    mass = NULL;
 
-  if (!origin && P->ifbox==0) {
+  if (!origin && P->BoxType==0) {
     mprintf("    Error: Center::setup: Box center specified but no box information.\n");
     //fprintf(stdout,"                            Centering on origin.\n");
     return 1;
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Closest.cpp amber11/AmberTools/src/cpptraj/src/Action_Closest.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Closest.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Closest.cpp	2011-10-25 15:01:28.108288642 +0300
@@ -181,8 +181,8 @@
   // NOTE: Should box be figured out from read-in coords?
   imageType = 0;
   if (!noimage) {
-    imageType = P->ifbox;
-    if (P->ifbox==0) {
+    imageType = P->BoxType;
+    if (P->BoxType==0) {
         mprintf("    Warning: Closest::setup: ");
         mprintf(" Imaging specified but no box information in prmtop %s\n",P->parmName);
         mprintf("             No imaging can occur..\n");
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Distance.cpp amber11/AmberTools/src/cpptraj/src/Action_Distance.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Distance.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Distance.cpp	2011-10-25 15:01:28.194288563 +0300
@@ -57,8 +57,6 @@
   mprintf("    DISTANCE: %s to %s",Mask1.maskString, Mask2.maskString);
   if (noimage) 
     mprintf(", non-imaged");
-  else
-    mprintf(", imaged");
   if (useMass) 
     mprintf(", center of mass");
   else
@@ -68,6 +66,11 @@
   return 0;
 }
 
+/*
+ * Distance::setup()
+ * Determine what atoms each mask pertains to for the current parm file.
+ * Also determine whether imaging should be performed.
+ */
 int Distance::setup() {
 
   if ( Mask1.SetupMask(P,debug) ) return 1;
@@ -89,11 +92,19 @@
   // Check imaging - check box based on prmtop box
   imageType = 0;
   if (!noimage) {
-    imageType = P->ifbox;
-    if (P->ifbox==0 && debug>0) {
+    imageType = P->BoxType;
+    if (P->BoxType==0 && debug>0) {
       mprintf("    Warning: No box info in %s, disabling imaging.\n",P->parmName);
     }
   }
+
+  // Print imaging info for this parm
+  mprintf("    DISTANCE: %s to %s",Mask1.maskString, Mask2.maskString);
+  if (imageType > 0)
+    mprintf(", imaged");
+  else
+    mprintf(", imaging off");
+  mprintf(".\n");
         
   return 0;  
 }
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_DSSP.cpp amber11/AmberTools/src/cpptraj/src/Action_DSSP.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Action_DSSP.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_DSSP.cpp	2011-10-25 15:01:28.195288561 +0300
@@ -76,7 +76,7 @@
   int selected, atom, res;
   Residue RES;
 
-  // Set up mask
+  // Set up mask for this parm
   if ( Mask.SetupMask(P,debug) ) return 1;
   if ( Mask.None() ) {
     mprintf("      Error: DSSP::setup: Mask has no atoms.\n");
@@ -90,25 +90,25 @@
     Nres=P->nres;
   //mprintf("      DSSP: Setting up for %i residues.\n",Nres);
 
-  // Free up SecStruct if previously allocated.
-  // NOTE: In action setup, should check if Parm has really changed...
-  SecStruct.clear();
+  // Set up for each residue of the current Parm if not already set-up.
   for (res = 0; res < Nres; res++) {
-    RES.sstype=SECSTRUCT_NULL;
-    RES.isSelected=false;
-    RES.C=-1;
-    RES.O=-1;
-    RES.N=-1;
-    RES.H=-1;
-    RES.CO_HN_Hbond.assign( Nres, 0 );
-    RES.SSprob[0]=0.0;
-    RES.SSprob[1]=0.0;
-    RES.SSprob[2]=0.0;
-    RES.SSprob[3]=0.0;
-    RES.SSprob[4]=0.0;
-    RES.SSprob[5]=0.0;
-    RES.SSprob[6]=0.0;
-    SecStruct.push_back(RES);
+    if (res>=(int)SecStruct.size()) {
+      RES.sstype=SECSTRUCT_NULL;
+      RES.isSelected=false;
+      RES.C=-1;
+      RES.O=-1;
+      RES.N=-1;
+      RES.H=-1;
+      RES.CO_HN_Hbond.assign( Nres, 0 );
+      RES.SSprob[0]=0.0;
+      RES.SSprob[1]=0.0;
+      RES.SSprob[2]=0.0;
+      RES.SSprob[3]=0.0;
+      RES.SSprob[4]=0.0;
+      RES.SSprob[5]=0.0;
+      RES.SSprob[6]=0.0;
+      SecStruct.push_back(RES);
+    }
   }
 
   // Go through all atoms in mask. Set up a residue for each C, O, N, and H atom
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Image.cpp amber11/AmberTools/src/cpptraj/src/Action_Image.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Image.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Image.cpp	2011-10-25 15:01:28.110288640 +0300
@@ -98,14 +98,14 @@
     useMass = false;
   }
 
-  if (P->ifbox==0) {
+  if (P->BoxType==0) {
     mprintf("    Error: Image::setup: Parm %s does not contain box information.\n",
             P->parmName);
     return 1;
   }
 
   ortho = false;  
-  if (P->ifbox==1 && triclinic==OFF) ortho=true;
+  if (P->BoxType==1 && triclinic==OFF) ortho=true;
 
   if (triclinic == FAMILIAR) {
     if (ComMask!=NULL) {
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Outtraj.cpp amber11/AmberTools/src/cpptraj/src/Action_Outtraj.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Outtraj.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Outtraj.cpp	2011-10-25 15:01:28.129288623 +0300
@@ -6,6 +6,9 @@
 // CONSTRUCTOR
 Outtraj::Outtraj() {
   //fprintf(stderr,"Outtraj Con\n");
+  min=0.0;
+  max=0.0;
+  Dset=NULL;
 } 
 
 // DESTRUCTOR
@@ -13,11 +16,40 @@
 
 /*
  * Outtraj::init()
- * Action wrapper for trajout
+ * Action wrapper for trajout.
+ * Expected call: outtraj <filename> [ trajout args ] 
+ *                        [maxmin <dataset> min <min> max <max>
  */
 int Outtraj::init() {
+  char *datasetName;
+
+#ifdef MPI
+  mprintf("ERROR: OUTTRAJ currently not functional with MPI.\n");
+  return 1;
+#endif
+
+  mprintf("    OUTTRAJ: Will write to [%s]\n",A->Arg(1));
+  outtraj.SetDebug(debug);
+  // If maxmin, get the name of the dataset as well as the max and min values.
+  datasetName = A->getKeyString("maxmin",NULL);
+  if (datasetName!=NULL) {
+    Dset = DSL->Get(datasetName);
+    if (Dset==NULL) {
+      mprintf("Error: Outtraj maxmin: Could not get dataset %s\n",datasetName);
+      return 1;
+    } else {
+      // Currently dont allow for string datasets
+      if (Dset->Type()==STRING) {
+        mprintf("Error: Outtraj maxmin: String dataset (%s) not supported.\n",datasetName);
+        return 1;
+      }
+      max = A->getKeyDouble("max",0.0);
+      min = A->getKeyDouble("min",0.0);
+      mprintf("             maxmin: Printing trajectory frames based on %lf <= %s <= %lf\n",
+              min, datasetName, max);
+    }
+  }
 
-  mprintf("    OUTTRAJ: [%s]\n",A->ArgLine());
   return ( outtraj.Add(A,PFL,worldsize) );
 } 
 
@@ -33,8 +65,32 @@
  * Outtraj::action()
  */
 int Outtraj::action() {
+  double dVal;
+  int iVal;
 
-  return ( outtraj.Write(currentFrame, F, P) );
+  // If dataset defined, check if frame is within max/min
+  if (Dset!=NULL) {
+    if (Dset->Type() == DOUBLE) {
+      if (Dset->Get(&dVal, currentFrame)) return 1;
+    } else if (Dset->Type() == INT) {
+      if (Dset->Get(&iVal, currentFrame)) return 1;
+      dVal = (double) iVal;
+    } else
+      return 1;
+    //mprintf("DBG: maxmin: dVal = %lf\n",dVal);
+    // If value from dataset not within min/max, exit now.
+    if (dVal < min || dVal > max) return 0;
+  }
+  if ( outtraj.Write(currentFrame, F, P) != 0 ) return 1;
+  return 0;
 } 
 
+/*
+ * Outtraj::print()
+ * Close trajectory.
+ */
+void Outtraj::print() {
+  mprintf("  OUTTRAJ: [%s] Wrote %i frames.\n",A->Arg(1),outtraj.front()->CurrentFrame());
+  outtraj.Close();
+}
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Outtraj.h amber11/AmberTools/src/cpptraj/src/Action_Outtraj.h
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Outtraj.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Outtraj.h	2011-10-25 15:01:28.129288623 +0300
@@ -6,6 +6,9 @@
 
 class Outtraj: public Action {
     TrajoutList outtraj;
+    double max;
+    double min;
+    DataSet *Dset;
   public:
     Outtraj();
     ~Outtraj();
@@ -13,5 +16,6 @@
     int init();
     //int setup();
     int action();
+    void print();
 };
 #endif
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Rms2d.cpp amber11/AmberTools/src/cpptraj/src/Action_Rms2d.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Rms2d.cpp	1970-01-01 03:00:00.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Rms2d.cpp	2011-10-25 15:01:28.074288674 +0300
@@ -0,0 +1,71 @@
+// Rms2d 
+#include "Action_Rms2d.h"
+#include "CpptrajStdio.h"
+
+// CONSTRUCTOR
+Rms2d::Rms2d() {
+  //fprintf(stderr,"Rms2d Con\n");
+  nofit=false;
+  useMass=false;
+} 
+
+// DESTRUCTOR
+Rms2d::~Rms2d() { }
+
+/*
+ * Rms2d::init()
+ * Expected call: rms2d <mask> <refmask> [rmsout filename] [mass] [nofit]
+ * Dataset name will be the last arg checked for. Check order is:
+ *    1) Keywords
+ *    2) Masks
+ *    3) Dataset name
+ */
+int Rms2d::init() {
+  char *mask0, *maskRef;
+
+  // Get keywords
+  nofit = A->hasKey("nofit");
+  useMass = A->hasKey("mass");
+  rmsdFile = A->getKeyString("rmsout",NULL);
+
+  // Get the RMS mask string for frames
+  mask0 = A->getNextMask();
+  FrameMask.SetMaskString(mask0);
+  // Get RMS mask string for reference
+  maskRef = A->getNextMask();
+  // If no reference mask specified, make same as RMS mask
+  if (maskRef==NULL) maskRef=mask0;
+  RefMask.SetMaskString(maskRef);
+
+  mprintf("    RMS2D: (%s) to (%s)",FrameMask.maskString,RefMask.maskString);
+  if (nofit)
+    mprintf(" (no fitting)");
+  if (useMass)
+    mprintf(" (mass-weighted)");
+  if (rmsdFile!=NULL) 
+    mprintf(" output to %s",rmsdFile);
+  mprintf("\n");
+
+  return 0;
+}
+
+/*
+ * Rms2d::setup()
+ * Not important for Rms2d, initial pass is only for storing frames.
+ */
+int Rms2d::setup() {
+  return 0;  
+}
+
+/*
+ * Rms2d::action()
+ * Store current frame as a reference frame.
+ */
+int Rms2d::action() {
+
+  ReferenceFrames.Add(F,P);
+  
+  return 0;
+} 
+
+
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Rms2d.h amber11/AmberTools/src/cpptraj/src/Action_Rms2d.h
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Rms2d.h	1970-01-01 03:00:00.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Rms2d.h	2011-10-25 15:01:28.075288673 +0300
@@ -0,0 +1,21 @@
+#ifndef INC_ACTION_RMS2D_H
+#define INC_ACTION_RMS2D_H
+// Rms2d
+#include "Action.h"
+
+class Rms2d: public Action {
+    FrameList ReferenceFrames;
+    bool nofit;
+    bool useMass;
+    AtomMask RefMask;
+    AtomMask FrameMask;
+    char *rmsdFile;
+  public:
+    Rms2d();
+    ~Rms2d();
+
+    int init();
+    int setup();
+    int action();
+};
+#endif
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Action_Rmsd.cpp amber11/AmberTools/src/cpptraj/src/Action_Rmsd.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Action_Rmsd.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Action_Rmsd.cpp	2011-10-25 15:01:28.229288531 +0300
@@ -256,6 +256,7 @@
     PerResRMSD=new DataSetList();
     resName[4]='\0';
     for (it=ResRange.begin(); it!=ResRange.end(); it++) {
+      //res = *it - 1; // res is the internal resnumber, *it the user resnumber
       // Get corresponding reference resnum - if none specified use current res
       if (RefRange.empty()) 
         refRes = (*it);
@@ -263,7 +264,18 @@
         refRes = RefRange.front();
         RefRange.pop_front();
       }
-      //res = *it - 1; // res is the internal resnumber, *it the user resnumber
+
+      // Check if either the residue num or the reference residue num out of range.
+      if ( (*it) < 1 || (*it) > P->nres) {
+        mprintf("    Warning: Rmsd: perres: Specified residue # %i is out of range.\n",*it);
+        continue;
+      }
+      if ( refRes < 1 || refRes > P->nres ) {
+        mprintf("    Warning: Rmsd: perres: Specified reference residue # %i is out of range.\n",
+                refRes);
+        continue;
+      }
+
       // Setup Dataset Name to be name of this residue 
       P->ResName(resName,(*it)-1);
       
diff -urN amber11.orig/AmberTools/src/cpptraj/src/AmberNetcdf.cpp amber11/AmberTools/src/cpptraj/src/AmberNetcdf.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/AmberNetcdf.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/AmberNetcdf.cpp	2011-10-25 15:01:28.131288621 +0300
@@ -49,6 +49,7 @@
  * and close calls.
  */
 void AmberNetcdf::close() {
+  if (ncid<0) return;
   checkNCerr(nc_close(ncid),"Closing netcdf file.");
   if (debug>0) rprintf("Successfully closed ncid %i\n",ncid);
   ncid=-1;
@@ -92,8 +93,10 @@
  * Open the netcdf file, read all dimension and variable IDs, close. 
  */
 int AmberNetcdf::SetupRead() {
-  char *attrText; // For checking conventions and version 
-  int spatial; // For checking spatial dimensions
+  char *attrText;            // For checking conventions and version 
+  int spatial;               // For checking spatial dimensions
+  double box[6];             // For checking box type
+  size_t start[3], count[3]; // For checking box type
 
   if (open()) return 1;
 
@@ -147,15 +150,15 @@
   if ( nc_inq_varid(ncid,"cell_lengths",&cellLengthVID)==NC_NOERR ) {
     if (checkNCerr(nc_inq_varid(ncid,"cell_angles",&cellAngleVID),
       "Getting cell angles.")!=0) return 1;
-    if (debug>0) mprintf("  Netcdf Box information found.\n"); 
-    if (P->ifbox==0) {
-      mprintf("Warning: Netcdf file contains box info but no box info found\n");
-      mprintf("         in associated parmfile %s; defaulting to orthogonal.\n",
-              P->parmName);
-      isBox=1;
-    } else {
-      isBox=P->ifbox;
-    }
+    if (debug>0) mprintf("  Netcdf Box information found.\n");
+    // Determine box type from angles
+    start[0]=0; start[1]=0; start[2]=0; 
+    count[0]=1; count[1]=3; count[2]=0;
+    if ( checkNCerr(nc_get_vara_double(ncid, cellLengthVID, start, count, box),
+                    "Getting cell lengths.")!=0 ) return 1;
+    if ( checkNCerr(nc_get_vara_double(ncid, cellAngleVID, start, count, box+3),
+                    "Getting cell angles.")!=0 ) return 1;
+    CheckBoxType(box);
   } 
 
   // Replica Temperatures
@@ -258,7 +261,7 @@
     "Defining cell angular variable.")) return 1;
 
   // Box Info
-  if (isBox>0) {
+  if (BoxType!=0) {
     dimensionID[0]=frameDID;
     dimensionID[1]=cell_spatialDID;
     if (checkNCerr(nc_def_var(ncid,"cell_lengths",NC_DOUBLE,2,dimensionID,&cellLengthVID),
@@ -362,7 +365,7 @@
                   "Getting frame %i",set)!=0 ) return 1;
 
   // Read box info 
-  if (isBox!=0) {
+  if (BoxType!=0) {
     count [1]=3;
     count [2]=0;
     if ( checkNCerr(nc_get_vara_double(ncid, cellLengthVID, start, count, F->box),
@@ -399,7 +402,7 @@
   F->frameToFloat(Coord);
 
   // write coords
-  start[0]=set;
+  start[0]=currentFrame;
   start[1]=0;
   start[2]=0;
   count[0]=1;
@@ -409,7 +412,7 @@
     "Netcdf Writing frame %i",set)) return 1;
 
   // write box
-  if (isBox>0 && cellLengthVID!=-1) {
+  if (BoxType!=0 && cellLengthVID!=-1) {
     count[1]=3;
     count[2]=0;
     if (checkNCerr(nc_put_vara_double(ncid,cellLengthVID,start,count,F->box),
@@ -427,6 +430,8 @@
   
   nc_sync(ncid); // Necessary after every write??
 
+  currentFrame++;
+
   return 0;
 }  
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/AmberParm.cpp amber11/AmberTools/src/cpptraj/src/AmberParm.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/AmberParm.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/AmberParm.cpp	2011-10-25 15:01:28.231288529 +0300
@@ -1,6 +1,12 @@
 /* AmberParm.cpp
- * Class that holds parameter information. Can be read in from Amber Topology
- * or PDB files.
+ * Class that holds parameter information. Can be read in from Amber Topology,
+ * PDB, or Mol2 files (implemented in the ReadParmXXX functions). The following
+ * parameters of AmberParm must always be set:
+ *   The NATOM, NRES, and IFBOX entries of the values array.
+ *   The names, resnames, resnums arrays.
+ *   The natom and nres variables.
+ * NOTES:
+ *   Eventually make the mol2 read parm function use the AddBond function.
  */
 #include <cstdlib>
 #include <cstring>
@@ -11,7 +17,7 @@
 #include "CpptrajStdio.h"
 
 #define AMBERPOINTERS 31
-
+#define TRUNCOCTBETA 109.4712206344906917365733534097672
 #define ELECTOAMBER 18.2223
 #define AMBERTOELEC 1/ELECTOAMBER
 // =============================================================
@@ -21,7 +27,7 @@
  * Given a residue number, set buffer with residue name. Replace blanks with _
  */
 void AmberParm::ResName(char *buffer, int res) {
-  if (res<0 || res>nres) return;
+  if (res<0 || res>=nres) return;
   strcpy(buffer, resnames[res]);
   if (buffer[3]==' ') buffer[3]='_';
 }
@@ -203,7 +209,9 @@
   bondsh=NULL;   
   types=NULL;   
   atomsPerMol=NULL; 
-  Box=NULL;    
+  Box[0]=0.0; Box[1]=0.0; Box[2]=0.0;
+  Box[3]=0.0; Box[4]=0.0; Box[5]=0.0;
+  BoxType=0; 
   pindex=0;      
   parmFrames=0; 
   outFrame=0;
@@ -217,7 +225,6 @@
   solventMoleculeStop=NULL;
   natom=0;      
   nres=0; 
-  ifbox=0; 
   parmName=NULL; 
   SurfaceInfo=NULL;
 }
@@ -234,7 +241,6 @@
   if (bonds!=NULL) free(bonds);
   if (bondsh!=NULL) free(bondsh);
   if (atomsPerMol!=NULL) free(atomsPerMol);
-  if (Box!=NULL) free(Box);
   if (solventMoleculeStart!=NULL) free(solventMoleculeStart);
   if (solventMoleculeStop!=NULL) free(solventMoleculeStop);
   if (solventMask!=NULL) free(solventMask);
@@ -271,54 +277,7 @@
   return NULL;
 }
 
-/* 
- * AmberParm::OpenParm()
- * Attempt to open file and read in parameters.
- */
-int AmberParm::OpenParm(char *filename) {
-  if ( File.SetupFile(filename,READ,UNKNOWN_FORMAT, UNKNOWN_TYPE,debug) ) return 1;
-
-  // Copy parm filename to parmName. Separate from File.filename in case of stripped parm
-  parmName=(char*) malloc( (strlen(File.basefilename)+1) * sizeof(char));
-  strcpy(parmName,File.basefilename);
-
-  if ( File.OpenFile() ) return 1;
-
-  switch (File.fileFormat) {
-    case AMBERPARM : if (ReadParmAmber()) return 1; break;
-    case PDBFILE   : if (ReadParmPDB()  ) return 1; break;
-    case MOL2FILE  : if (ReadParmMol2() ) return 1; break;
-    default: 
-      rprintf("Unknown parameter file type: %s\n",File.filename);
-      return 1;
-  }
-
-  File.CloseFile();
-
-  // Create a last dummy residue in resnums that holds natom, which would be
-  // the atom number of the next residue if it existed. Atom #s in resnums
-  // should correspond with cpptraj atom #s (start from 0) instead of Amber
-  // atom #s (start from 1). 
-  // Do this to be consistent with ptrajmask selection behavior - saves an 
-  // if-then statement.
-  resnums=(int*) realloc(resnums,(nres+1)*sizeof(int));
-  resnums[nres]=natom;
-  // DEBUG
-  //fprintf(stdout,"==== DEBUG ==== Resnums for %s:\n",File.filename);
-  //for (err=0; err<nres; err++) 
-  //  fprintf(stdout,"    %i: %i\n",err,resnums[err]);
-
-  // Set up solvent information
-  SetSolventInfo();
-
-  if (debug>0) {
-    mprintf("  Number of atoms= %i\n",natom);
-    mprintf("  Number of residues= %i\n",nres);
-  }
-
-  return 0;
-}
-
+// ---------========= ROUTINES PERTAINING TO SURFACE AREA =========---------
 /*
  * AmberParm::AssignLCPO()
  * Assign parameters for LCPO method. All radii are incremented by 1.4 Ang.
@@ -478,6 +437,7 @@
   return 0;
 }
 
+// ---------========= ROUTINES PERTAINING TO SOLVENT INFO =========---------
 /*
  * AmberParm::SetSolventInfo()
  * Assuming atomsPerMol has been read in, set solvent information.
@@ -536,7 +496,56 @@
 
   return 0; 
 }
-     
+    
+// --------========= ROUTINES PERTAINING TO READING PARAMETERS =========--------
+/* 
+ * AmberParm::OpenParm()
+ * Attempt to open file and read in parameters.
+ */
+int AmberParm::OpenParm(char *filename) {
+  if ( File.SetupFile(filename,READ,UNKNOWN_FORMAT, UNKNOWN_TYPE,debug) ) return 1;
+
+  // Copy parm filename to parmName. Separate from File.filename in case of stripped parm
+  parmName=(char*) malloc( (strlen(File.basefilename)+1) * sizeof(char));
+  strcpy(parmName,File.basefilename);
+
+  if ( File.OpenFile() ) return 1;
+
+  switch (File.fileFormat) {
+    case AMBERPARM : if (ReadParmAmber()) return 1; break;
+    case PDBFILE   : if (ReadParmPDB()  ) return 1; break;
+    case MOL2FILE  : if (ReadParmMol2() ) return 1; break;
+    default: 
+      rprintf("Unknown parameter file type: %s\n",File.filename);
+      return 1;
+  }
+
+  File.CloseFile();
+
+  // Create a last dummy residue in resnums that holds natom, which would be
+  // the atom number of the next residue if it existed. Atom #s in resnums
+  // should correspond with cpptraj atom #s (start from 0) instead of Amber
+  // atom #s (start from 1). 
+  // Do this to be consistent with ptrajmask selection behavior - saves an 
+  // if-then statement.
+  resnums=(int*) realloc(resnums,(nres+1)*sizeof(int));
+  resnums[nres]=natom;
+  // DEBUG
+  //fprintf(stdout,"==== DEBUG ==== Resnums for %s:\n",File.filename);
+  //for (err=0; err<nres; err++) 
+  //  fprintf(stdout,"    %i: %i\n",err,resnums[err]);
+
+  // Set up solvent information
+  SetSolventInfo();
+
+  if (debug>0) {
+    mprintf("  Number of atoms= %i\n",natom);
+    mprintf("  Number of residues= %i\n",nres);
+  }
+
+  return 0;
+}
+
 /* 
  * AmberParm::ReadParmAmber() 
  * Read parameters from Amber Topology file
@@ -544,6 +553,7 @@
 int AmberParm::ReadParmAmber() {
   int err, atom;
   int *solvent_pointer;
+  double *boxFromParm;
 
   if (debug>0) mprintf("Reading Amber Topology file %s\n",parmName);
 
@@ -555,7 +565,6 @@
 
   natom=values[NATOM];
   nres=values[NRES];
-  ifbox=values[IFBOX];
   if (debug>0)
     mprintf("    Amber top contains %i atoms, %i residues.\n",natom,nres);
 
@@ -583,7 +592,8 @@
   if (bonds==NULL) {mprintf("Error in bonds w/o H.\n"); err++;}
   bondsh=(int*) getFlagFileValues("BONDS_INC_HYDROGEN",values[NBONH]*3);
   if (bondsh==NULL) {mprintf("Error in bonds inc H.\n"); err++;}
-  if (ifbox>0) {
+  // Get solvent info if IFBOX>0
+  if (values[IFBOX]>0) {
     solvent_pointer=(int*) getFlagFileValues("SOLVENT_POINTERS",3);
     if (solvent_pointer==NULL) {
       mprintf("Error in solvent pointers.\n"); 
@@ -596,12 +606,20 @@
     }
     atomsPerMol=(int*) getFlagFileValues("ATOMS_PER_MOLECULE",molecules);
     if (atomsPerMol==NULL) {mprintf("Error in atoms per molecule.\n"); err++;}
-    Box=(double*) getFlagFileValues("BOX_DIMENSIONS",4);
-    if (Box==NULL) {mprintf("Error in Box information.\n"); err++;}
+    // boxFromParm = {OLDBETA, BOX(1), BOX(2), BOX(3)}
+    boxFromParm=(double*) getFlagFileValues("BOX_DIMENSIONS",4);
+    if (boxFromParm==NULL) {mprintf("Error in Box information.\n"); err++;}
+    // Determine box type: 1-Ortho, 2-Nonortho
+    SetBoxInfo(boxFromParm[0],boxFromParm[1],boxFromParm[2],boxFromParm[3]);
+    free(boxFromParm);
     if (debug>0) {
       mprintf("    %s contains box info: %i mols, first solvent mol is %i\n",
               parmName, molecules, firstSolvMol);
-      mprintf("    BOX: %lf %lf %lf %lf\n",Box[0],Box[1],Box[2],Box[3]);
+      mprintf("    BOX: %lf %lf %lf | %lf %lf %lf\n",Box[0],Box[1],Box[2],Box[3],Box[4],Box[5]);
+      if (BoxType==1)
+        mprintf("         Box is orthogonal.\n");
+      else
+        mprintf("         Box is non-orthogonal.\n");
     }
   }
 
@@ -686,6 +704,7 @@
   values = (int*) calloc(AMBERPOINTERS, sizeof(int));
   values[NATOM] = natom;
   values[NRES] = nres;
+  values[IFBOX] = 0;
 
   if (debug>0) 
     mprintf("    PDB contains %i atoms, %i residues, %i molecules.\n",
@@ -799,6 +818,7 @@
   values[NRES] = nres;
   values[NBONH] = numbondsh;
   values[MBONA] = numbonds;
+  values[IFBOX] = 0;
 
   mprintf("    Mol2 contains %i atoms, %i residues,\n", natom,nres);
   mprintf("    %i bonds to H, %i other bonds.\n", numbondsh,numbonds);
@@ -806,6 +826,61 @@
   return 0;
 }
 
+// ---------===========================================================---------
+/*
+ * AmberParm::SetBoxInfo()
+ * Given 3 box lengths and an angle determine the box type and set
+ * the box information. If called with negative beta, set no box.
+ * Currently recognized betas:
+ *   90.00 - Orthogonal
+ *  109.47 - Truncated octahedral
+ *   60.00 - Rhombic dodecahedron
+ * Any other beta just sets all angles to beta and a warning is printed.
+ */
+int AmberParm::SetBoxInfo(double beta, double bx, double by, double bz)  {
+  int ifbox=0;
+
+  // Determine box type from beta (none, ortho, non-ortho (truncated oct/triclinic)
+  if (beta<=0.0) {
+    if (BoxType>0) 
+      mprintf("    %s: Removing box information.\n",parmName);
+    BoxType=0;
+    ifbox=0;
+    Box[0]=0.0; Box[1]=0.0; Box[2]=0.0;
+    Box[3]=0.0; Box[4]=0.0; Box[5]=0.0;
+  } else if (beta == 90.0) {
+    BoxType=1;
+    ifbox=1;
+    Box[0]=bx; Box[1]=by; Box[2]=bz;
+    Box[3]=90.0; Box[4]=90.0; Box[5]=90.0;
+    if (debug>0) mprintf("    %s: Setting box to be orthogonal.\n",parmName);
+  } else if (beta > 109.47 && beta < 109.48) {
+    BoxType=2;
+    ifbox=2;
+    Box[0]=bx; Box[1]=by; Box[2]=bz;
+    //Box[3] = TRUNCOCTBETA;
+    Box[3] = beta;
+    Box[4]=Box[3]; Box[5]=Box[3];
+    if (debug>0) mprintf("    %s: Setting box to be a truncated octahedron, angle is %lf\n",
+                         parmName,Box[3]);
+  } else if (beta == 60.0) {
+    BoxType=2;
+    ifbox=1;
+    Box[0]=bx; Box[1]=by; Box[2]=bz;
+    Box[3]=60.0; Box[4]=90.0; Box[5]=60.0;
+    if (debug>0) 
+      mprintf("    %s: Setting box to be a rhombic dodecahedron, alpha=gamma=60.0, beta=90.0\n",
+              parmName);
+  } else {
+    BoxType=2;
+    ifbox=1;
+    Box[0]=bx; Box[1]=by; Box[2]=bz;
+    Box[3]=beta; Box[4]=beta; Box[5]=beta;
+    mprintf("    Warning: %s: Unrecognized box type, beta is %lf\n",beta);
+  }
+  return 0;  
+}
+
 /*
  * AmberParm::AtomInfo()
  * Print parm information for atom.
@@ -829,8 +904,8 @@
  */
 void AmberParm::Info(char *buffer) {
 
-  sprintf(buffer,"%i atoms, %i res, box %i, %i mol, %i solvent mol, %i frames",
-          natom,nres,ifbox,molecules,solventMolecules,parmFrames);
+  sprintf(buffer,"%i atoms, %i res, boxtype %i, %i mol, %i solvent mol, %i frames",
+          natom,nres,BoxType,molecules,solventMolecules,parmFrames);
 }
   
 // NOTE: The following atomToX functions do not do any memory checks!
@@ -963,6 +1038,7 @@
   return bonds;
 }
 
+// ---------===========================================================---------
 /*
  * AmberParm::modifyStateByMap()
  * Currently only intended for use with AtomMap.
@@ -1028,24 +1104,21 @@
   // Set up new parm information
   newParm->natom = this->natom;
   newParm->nres = this->nres;
-  newParm->ifbox = this->ifbox;
   newParm->parmFrames = this->parmFrames;
 
   // Give mapped parm the same pindex as original parm
   newParm->pindex = this->pindex;
 
   // Copy box information
-  if (this->Box!=NULL) {
-    newParm->Box=(double*) malloc(4*sizeof(double));
-    for (int i=0; i<4; i++)
-      newParm->Box[i] = this->Box[i];
-  }
+  for (int i=0; i<6; i++)
+    newParm->Box[i] = this->Box[i];
+  newParm->BoxType=this->BoxType;
 
   // Set values up
   // NOTE: Eventually set all pointers up?
   newParm->values[NATOM] = newParm->natom;
   newParm->values[NRES] = newParm->nres;
-  newParm->values[IFBOX] = newParm->ifbox;
+  newParm->values[IFBOX] = this->values[IFBOX];
 
   return newParm;
 }
@@ -1152,7 +1225,6 @@
   // Set up new parm information
   newParm->natom = j;
   newParm->nres = jres+1; 
-  newParm->ifbox = this->ifbox;
   newParm->parmFrames = this->parmFrames;
   if (this->molecules>0) 
     newParm->molecules = jmol+1;
@@ -1184,26 +1256,25 @@
   }
   
   // Copy box information
-  if (this->Box!=NULL) {
-    newParm->Box=(double*) malloc(4*sizeof(double));
-    for (i=0; i<4; i++)
-      newParm->Box[i] = this->Box[i];
-  }
+  for (i=0; i<6; i++)
+    newParm->Box[i] = this->Box[i];
+  newParm->BoxType=this->BoxType;
 
   // Set values up
   // NOTE: Eventually set all pointers up?
   newParm->values[NATOM] = newParm->natom;
   newParm->values[NRES] = newParm->nres;
-  newParm->values[IFBOX] = newParm->ifbox;
+  newParm->values[IFBOX] = this->values[IFBOX];
 
   mprintf("           New parmtop contains %i atoms.\n",newParm->natom);
   mprintf("                                %i residues.\n",newParm->nres);
   mprintf("                                %i molecules.\n",newParm->molecules);
-  mprintf("                                %i solvent molcules.\n",newParm->solventMolecules);
+  mprintf("                                %i solvent molecules.\n",newParm->solventMolecules);
 
   return newParm;
 }
 
+// ---------===========================================================---------
 /* 
  * AmberParm::DataToBuffer()
  * Return char buffer containing N data elements stored in I, D, or C with 
@@ -1267,6 +1338,7 @@
   char *buffer;
   int solvent_pointer[3];
   int atom;
+  double parmBox[4];
 
   if (parmName==NULL) return 1;
 
@@ -1346,7 +1418,7 @@
   }
 
   // SOLVENT POINTERS
-  if (ifbox>0) {
+  if (values[IFBOX]>0) {
     PrintFlagFormat(&outfile, "%FLAG SOLVENT_POINTERS", "%FORMAT(3I8)");
     solvent_pointer[0]=finalSoluteRes;
     solvent_pointer[1]=molecules;
@@ -1360,8 +1432,12 @@
     outfile.IO->Write(buffer, sizeof(char), BufferSize);
 
     // BOX DIMENSIONS
+    parmBox[0] = Box[4]; // beta
+    parmBox[1] = Box[0]; // boxX
+    parmBox[2] = Box[1]; // boxY
+    parmBox[3] = Box[2]; // boxZ
     PrintFlagFormat(&outfile, "%FLAG BOX_DIMENSIONS", "%FORMAT(5E16.8)");
-    buffer = DataToBuffer(buffer,"%FORMAT(5E16.8)", NULL, Box, NULL, 4);
+    buffer = DataToBuffer(buffer,"%FORMAT(5E16.8)", NULL, parmBox, NULL, 4);
     outfile.IO->Write(buffer, sizeof(char), BufferSize);
   }
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/AmberParm.h amber11/AmberTools/src/cpptraj/src/AmberParm.h
--- amber11.orig/AmberTools/src/cpptraj/src/AmberParm.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/AmberParm.h	2011-10-25 15:01:28.117288634 +0300
@@ -75,14 +75,14 @@
     int *resnums;         // IPRES(NRES) 
     int natom;            // NATOM
     int nres;             // NRES
-    int ifbox;            // IFBOX
     int finalSoluteRes;   // IPTRES
     int molecules;        // NSPM
     int firstSolvMol;     // NSPSOL
     int *atomsPerMol;     // NSP(NSPM)
     double *mass;         // AMASS(NATOM)
     double *charge;       // CHARGE(NATOM)
-    double *Box;          // OLDBETA, BOX(1), BOX(2), BOX(3)
+    double Box[6];        // X, Y, Z, alpha, beta, gamma 
+    int BoxType;          // 0: None, 1: Orthogonal, 2: Non-orthogonal
     // From Ptraj
     char *solventMask;         // T for atoms in the solvent
     int solventMolecules;      // number of solvent molecules
@@ -96,6 +96,7 @@
     ~AmberParm();
     void ResName(char *, int);
     int OpenParm(char *);
+    int SetBoxInfo(double,double,double,double);
     int SetSurfaceInfo();
     int SetSolventInfo();
     void AtomInfo(int);
diff -urN amber11.orig/AmberTools/src/cpptraj/src/AmberRestart.cpp amber11/AmberTools/src/cpptraj/src/AmberRestart.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/AmberRestart.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/AmberRestart.cpp	2011-10-25 15:01:28.125288626 +0300
@@ -109,7 +109,7 @@
   frameSize+=frameSize;
 
   // If box coords are present, allocate extra space for them
-  if (isBox>0) {
+  if (BoxType!=0) {
     numBoxCoords=6;
     frameSize+=((numBoxCoords*12)+1);
   }
@@ -167,13 +167,12 @@
 
   // If 0 probably at EOF. No box or velo.
 //  } else if (lineSize==0) {
-    isBox=0;
+    BoxType=0;
     hasVelocity=0;
 
   // If 36 or 72 (+1 newline) box info.
   } else if (lineSize==37 || lineSize==73) {
-    isBox=1;
-    numBoxCoords = (lineSize-1) / 12;
+    getBoxType(frameBuffer,lineSize);
     hasVelocity=0;
 
   // If filled framebuffer again, has velocity info. Check for box after velocity.
@@ -182,15 +181,14 @@
     if (File->IO->Gets(buffer,82)==0) {
       lineSize=strlen(buffer);
       if (lineSize==37 || lineSize==73) {
-        isBox=1;
-        numBoxCoords = (lineSize-1) / 12;
+        getBoxType(buffer,lineSize);
       } else {
         mprintf("Error: AmberRestart::SetupRead():\n");
         mprintf("       Expect only 3 or 6 box coords in box coord line.\n");
         return 1;
       }
     } else
-      isBox=0;
+      BoxType=0;
 
   // Otherwise, who knows what was read?
   } else {
@@ -202,12 +200,12 @@
 
   // Recalculate the frame size
   if (hasVelocity) frameSize+=frameSize;
-  if (isBox) frameSize+=( (numBoxCoords*12) + 1 );
+  if (BoxType!=0) frameSize+=( (numBoxCoords*12) + 1 );
   frameBuffer=(char*) realloc(frameBuffer, frameSize*sizeof(char));
 
   if (debug > 0) {
-    mprintf("    Amber Restart isBox=%i hasVelocity=%i numBoxCoords=%i\n",
-            isBox,hasVelocity,numBoxCoords);
+    mprintf("    Amber Restart BoxType=%i hasVelocity=%i numBoxCoords=%i\n",
+            BoxType,hasVelocity,numBoxCoords);
     mprintf("    Amber Restart frameSize= %i\n",frameSize);
   }
   
@@ -221,6 +219,20 @@
 }
 
 /*
+ * AmberRestart::getBoxType()
+ * Based on input buffer, determine box type and num box coords.
+ */
+void AmberRestart::getBoxType(char *boxline, int boxlineSize) {
+  double box[6];
+  numBoxCoords = (boxlineSize-1) / 12;
+  if (numBoxCoords>3) {
+    sscanf(boxline, "%8lf%8lf%8lf%8lf%8lf%8lf",box,box+1,box+2,box+3,box+4,box+5);
+    CheckBoxType(box);
+  } else
+    BoxType = P->BoxType;
+}
+
+/*
  * AmberRestart::getFrame()
  * Get the restart file frame. If velocities are present, read those too.
  */
@@ -251,7 +263,7 @@
     //F->V->printAtomCoord(0);
   }
   // Convert box to Frame if present
-  if (isBox) {
+  if (BoxType!=0) {
     if ( (bufferPosition = F->BufferToBox(bufferPosition, numBoxCoords, 12))==NULL ) {
       mprintf("Error: AmberRestart::getFrame: * detected in box coordinates of %s\n",
               trajfilename);
@@ -287,7 +299,7 @@
   if (F->V!=NULL)  // NOTE: Use hasVelocity in addition/instead?
     bufferPosition = F->V->FrameToBuffer(bufferPosition,"%12.7lf",12,6);
   // Write box to buffer
-  if (isBox)
+  if (BoxType!=0)
     bufferPosition = F->BoxToBuffer(bufferPosition, numBoxCoords, "%12.7lf",12);
 
   //if (seekable) fseek(fp, titleSize+(set*frameSize),SEEK_SET);
@@ -297,6 +309,8 @@
 
   File->IO->Close();
 
+  currentFrame++;
+
   return 0;
 }
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/AmberRestart.h amber11/AmberTools/src/cpptraj/src/AmberRestart.h
--- amber11.orig/AmberTools/src/cpptraj/src/AmberRestart.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/AmberRestart.h	2011-10-25 15:01:28.118288633 +0300
@@ -14,6 +14,7 @@
 
   int SetupRead();
   int SetupWrite();
+  void getBoxType(char *, int);
 
   public:
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/AmberRestartNC.cpp amber11/AmberTools/src/cpptraj/src/AmberRestartNC.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/AmberRestartNC.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/AmberRestartNC.cpp	2011-10-25 15:01:28.126288625 +0300
@@ -60,15 +60,8 @@
 /*
  * AmberRestartNC::open()
  * Open up Netcdf restart file and set all dimension and variable IDs.
- * This is done every time the file is opened up since Im not sure
- * the variable IDs stay the same throughout each opening.
- * Could eventually be separated.
- * NOTE: Replace attrText allocs with static buffer? 
  */
 int AmberRestartNC::open() {
-  char *attrText; // For checking conventions and version 
-  int spatial; // For checking spatial dimensions
-
   mprintf("DEBUG: AmberRestartNC::open() called for %s, ncid=%i\n",File->filename,ncid);
   // If already open, return
   if (ncid!=-1) return 0;
@@ -94,6 +87,23 @@
   // Netcdf files are always seekable
   seekable=1;
 
+  return 0;
+}
+
+/*
+ * AmberRestartNC::SetupRead()
+ * Set up netcdf restart file for reading, get all variable and dimension IDs. 
+ * Also check number of atoms against associated parmtop.
+ * NOTE: Replace attrText allocs with static buffer? 
+ */
+int AmberRestartNC::SetupRead() {
+  char *attrText; // For checking conventions and version 
+  int spatial; // For checking spatial dimensions
+  double box[6];
+  size_t start[2], count[2];
+
+  if (open()) return 1;
+
   // Get global attributes
   if (title==NULL) title = GetAttrText(ncid,NC_GLOBAL, "title");
   attrText = GetAttrText(ncid,NC_GLOBAL, "Conventions");
@@ -147,20 +157,18 @@
   mprintf("    Netcdf restart time= %lf\n",restartTime);
 
   // Box info
-  // NOTE: If no box info found in parm should really try to determine correct
-  //       box type from angles. 
   if ( nc_inq_varid(ncid,"cell_lengths",&cellLengthVID)==NC_NOERR ) {
     if (checkNCerr(nc_inq_varid(ncid,"cell_angles",&cellAngleVID),
       "Getting cell angles.")!=0) return 1;
-    if (debug>0) mprintf("  Netcdf restart Box information found.\n"); 
-    if (P->ifbox==0) {
-      mprintf("Warning: Netcdf restart file contains box info but no box info found\n");
-      mprintf("         in associated parmfile %s; defaulting to orthogonal.\n",
-              P->parmName);
-      isBox=1;
-    } else {
-      isBox=P->ifbox;
-    }
+    if (debug>0) mprintf("  Netcdf restart Box information found.\n");
+    // Determine box type from angles
+    start[0]=0; start[1]=0;
+    count[0]=3; count[1]=0; 
+    if ( checkNCerr(nc_get_vara_double(ncid, cellLengthVID, start, count, box),
+                    "Getting cell lengths.")!=0 ) return 1;
+    if ( checkNCerr(nc_get_vara_double(ncid, cellAngleVID, start, count, box+3),
+                    "Getting cell angles.")!=0 ) return 1;
+    CheckBoxType(box);
   } 
 
   // Replica Temperatures
@@ -175,15 +183,6 @@
   //int cell_spatialDID, cell_angularDID;
   //int spatialVID, cell_spatialVID, cell_angularVID;
 
-  return 0;
-}
-
-/*
- * AmberRestartNC::SetupRead()
- * Just a frontend to open for now. Also check number of atoms.
- */
-int AmberRestartNC::SetupRead() {
-  if (open()) return 1;
   if (ncatom!=P->natom) {
     mprintf("Warning: Number of atoms in NetCDF restart file %s (%i) does not\n",
             File->filename,ncatom);
@@ -210,7 +209,7 @@
  */
 int AmberRestartNC::setupWriteForSet(int set) {
   int dimensionID[NC_MAX_VAR_DIMS];
-  size_t start[3], count[3];
+  size_t start[2], count[2];
   char buffer[1024];
   char xyz[3];
   char abc[15] = { 'a', 'l', 'p', 'h', 'a', 
@@ -280,7 +279,7 @@
     "Defining cell angular variable.")) return 1;
 
   // Box Info
-  if (isBox>0) {
+  if (BoxType!=0) {
     dimensionID[0]=cell_spatialDID;
     if (checkNCerr(nc_def_var(ncid,"cell_lengths",NC_DOUBLE,1,dimensionID,&cellLengthVID),
       "Defining cell length variable.")) return 1;
@@ -388,9 +387,9 @@
   }
 
   // Read box info 
-  if (isBox!=0) {
-    count [0]=3;
-    count [1]=0;
+  if (BoxType!=0) {
+    count[0]=3;
+    count[1]=0;
     if ( checkNCerr(nc_get_vara_double(ncid, cellLengthVID, start, count, F->box),
                     "Getting cell lengths.")!=0 ) return 1;
     if ( checkNCerr(nc_get_vara_double(ncid, cellAngleVID, start, count, &(F->box[3])),
@@ -425,7 +424,7 @@
   }
 
   // write box
-  if (isBox>0 && cellLengthVID!=-1) {
+  if (BoxType!=0 && cellLengthVID!=-1) {
     count[0]=3;
     count[1]=0;
     if (checkNCerr(nc_put_vara_double(ncid,cellLengthVID,start,count,F->box),
@@ -439,6 +438,8 @@
   // Close file for this set
   close();
 
+  currentFrame++;
+
   return 0;
 }  
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/AmberTraj.cpp amber11/AmberTools/src/cpptraj/src/AmberTraj.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/AmberTraj.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/AmberTraj.cpp	2011-10-25 15:01:28.226288534 +0300
@@ -104,16 +104,18 @@
     rprintf("Error: AmberTraj::getFrame: * detected in coordinates of %s\n",trajfilename);
     return 1;  
   } 
-  if (isBox) { 
+  if (BoxType!=0) { 
     if ( (bufferPosition = F->BufferToBox(bufferPosition,numBoxCoords,8))==NULL ) {
       rprintf("Error: AmberTraj::getFrame: * detected in box coordinates of %s\n",
               trajfilename);
       return 1;
     }
-    // Set box angles to parmtop default
-    F->box[3] = P->Box[0];
-    F->box[4] = P->Box[0];
-    F->box[5] = P->Box[0];
+    // Set box angles to parmtop default if not read in
+    if (numBoxCoords==3) {
+      F->box[3] = P->Box[3];
+      F->box[4] = P->Box[4];
+      F->box[5] = P->Box[5];
+    }
   }
   return 0;
 }
@@ -138,20 +140,22 @@
   }
 
   bufferPosition = F->FrameToBuffer(bufferPosition,"%8.3lf",8,10);
-  if (isBox) 
+  if (BoxType!=0) 
     bufferPosition = F->BoxToBuffer(bufferPosition,numBoxCoords,"%8.3lf",8);
 
   outFrameSize = (int) (bufferPosition - frameBuffer);
   
   //if (seekable) 
   // NOTE: Seek only needs to happen when traj file changes
-  offset = (off_t) set;
-  offset *= (off_t) outFrameSize;
-  offset += (off_t) titleSize;
-  File->IO->Seek( offset);
+  //offset = (off_t) currentFrame;
+  //offset *= (off_t) outFrameSize;
+  //offset += (off_t) titleSize;
+  //File->IO->Seek( offset);
 
   if (File->IO->Write(frameBuffer,sizeof(char),outFrameSize)) return 1;
 
+  currentFrame++;
+ 
   return 0;
 }
 
@@ -163,8 +167,10 @@
 int AmberTraj::SetupRead() {
   char buffer[BUFFER_SIZE];
   int frame_lines;
-  int lineSize;
-  long long int file_size, frame_size;
+  int lineSize, maxi;
+  bool sizeFound;
+  long long int file_size, frame_size, title_size, tmpfsize;
+  double box[6]; // For checking box coordinates
 
   // Attempt to open the file. open() sets the title and titleSize
   if (open()) return 1;
@@ -219,7 +225,7 @@
 
     if (strncmp(buffer,"REMD",4)==0 || strncmp(buffer,"HREMD",5)==0) {
       // REMD header - no box coords
-      isBox=0;
+      BoxType=0;
     } else if (lineSize<80) {
       /* Line is shorter than 80 chars, indicates box coords.
        * Length of the line HAS to be a multiple of 8, and probably could be
@@ -228,53 +234,108 @@
        */
       if (debug>0) mprintf("    Box line is %i chars.\n",lineSize);
       if ( ((lineSize-1)%24)!=0 ) {
-        rprintf("Error in box coord line.\nExpect only 3 or 6 box coords.\n");
+        mprintf("Error in box coord line. Expect only 3 or 6 box coords.\n");
         return 1;
       }
       numBoxCoords=(lineSize-1) / 8;
       if (debug>0) mprintf("    Detected %i box coords.\n",numBoxCoords);
-      frameSize+=lineSize;
-      // Reallocate frame buffer accordingly
-      frameBuffer=(char*) realloc(frameBuffer,frameSize * sizeof(char));
-      if (P->ifbox==0) { 
-        rprintf( "Warning: Box coords detected in trajectory but not defined in topology!\n");
-        rprintf("         Setting box type to rectangular.\n");
-        isBox=1;
+      // Determine box type based on angles. Angles are usually not printed 
+      // for orthogonal and truncated octahedral boxes, but check here just
+      // to be safe. If no angles present use parmtop Box Type.
+      if (numBoxCoords>3) {
+        sscanf(buffer, "%8lf%8lf%8lf%8lf%8lf%8lf",box,box+1,box+2,box+3,box+4,box+5);
+        CheckBoxType(box);
       } else {
-        isBox = P->ifbox;
+        BoxType = P->BoxType; 
+        // If box coords are present in traj but no box in parm, print warning
+        if (BoxType == 0)
+          mprintf("Warning: %s has box coordinates but no box info in %s\n",
+                  trajfilename,P->parmName);
       }
+      // Reallocate frame buffer accordingly
+      frameSize+=lineSize;
+      frameBuffer=(char*) realloc(frameBuffer,frameSize * sizeof(char));
     }
   }
 
-  /* Calculate number of frames. If not possible and this is not a
-   * compressed file the trajectory is probably corrupted. Frames will
-   * be read until EOF.
-   * NOTE: It is necessary to use the stat command to get the file size
-   * instead of fseek in case the file has been popen'd.
-   * NOTE: Need the uncompressed file size!
-   */
-  if (File->uncompressed_size>0)
-    file_size = File->uncompressed_size;
-  else
-    file_size=File->file_size;
+  // Calculate Frames and determine seekable. If not possible and this is not a
+  // compressed file the trajectory is probably corrupted. Frames will
+  // be read until EOF (Frames = -1).
   if (debug>0)
-    rprintf("Title offset=%i FrameSize=%i UncompressedFileSize=%lli\n",
-            titleSize,frameSize,file_size);
-  frame_size = (long long int) titleSize;
-  file_size = file_size - frame_size; // Subtract title size from file total size.
+    rprintf("Title offset=%i FrameSize=%i Size=%lu UncompressedFileSize=%lu\n",
+            titleSize,frameSize,File->file_size,File->uncompressed_size);
+  title_size = (long long int) titleSize;
   frame_size = (long long int) frameSize;
-  Frames = (int) (file_size / frame_size);
-
-  if ( (file_size % frame_size) == 0 ) {
-    seekable = 1;
-    stop = Frames;
+  // -----==== AMBER TRAJ COMPRESSED ====------
+  if (File->compressType!=NONE) {
+    // If the uncompressed size of compressed file is reported as <= 0,
+    // uncompressed size cannot be determined. Read coordinates until
+    // EOF.
+    if (File->uncompressed_size <= 0) {
+      mprintf("Warning: %s: Uncompressed size of trajectory could not be determined.\n",
+              File->filename);
+      if (File->compressType==BZIP2)
+        mprintf("         (This is normal for bzipped files)\n");
+      mprintf("         Number of frames could not be calculated.\n");
+      mprintf("         Frames will be read until EOF.\n");
+      Frames = -1;
+      seekable = false;
+    } else {
+      file_size = File->uncompressed_size;
+      file_size = file_size - title_size;
+      // Frame calculation for large gzip files
+      // If uncompressed size is less than compressed size, uncompressed
+      // size is likely > 4GB.
+      if (File->compressType == GZIP && file_size < (long long int) File->file_size) {
+        // Since this is gzip compressed, if the file_size % frame size != 0, 
+        // it could be that the uncompressed filesize > 4GB. Since 
+        //   ISIZE = uncompressed % 2^32, 
+        // try ((file_size + (2^32 * i)) % frame_size) and see if any are 0.
+        if ( (file_size % frame_size) != 0) {
+          // Determine the maximum number of iterations to try based on the
+          // fact that Amber trajectories typically compress about 3x with
+          // gzip.
+          tmpfsize = ((File->file_size * 4) - File->uncompressed_size) / 4294967296LL;
+          maxi = (int) tmpfsize;
+          maxi++;
+          if (debug>1)
+            mprintf("\tLooking for uncompressed gzip size > 4GB, %i iterations.\n",maxi);
+          tmpfsize = 0;
+          sizeFound=false;
+          for (int i = 0; i < maxi; i++ ) {
+            tmpfsize = (4294967296LL * i) + file_size;
+            if ( (tmpfsize % frame_size) == 0) {sizeFound=true; break;}
+          }
+          if (sizeFound) file_size = tmpfsize;
+        }
+      }
+      if ((file_size % frame_size) == 0) {
+        Frames = (int) (file_size / frame_size);
+        seekable = true;
+      } else {
+        mprintf("Warning: %s: Number of frames in compressed traj could not be determined.\n",
+                File->filename);
+        mprintf("         Frames will be read until EOF.\n");
+        Frames=-1;
+        seekable=false;
+      }
+    }
+  // ----==== AMBER TRAJ NOT COMPRESSED ====----
   } else {
-    stop = -1;
-    Frames = -1;
-    seekable = 0;
-    mprintf("  Error: Could not predict # frames in %s. This usually indicates \n",File->filename);
-    mprintf("         a corrupted trajectory. Frames will be read until EOF.\n");
+    file_size = File->file_size;
+    file_size = file_size - title_size;
+    Frames = (int) (file_size / frame_size);
+    if ( (file_size % frame_size) == 0 ) {
+      seekable = true;
+    } else {
+      mprintf("Warning: %s: Could not accurately predict # frames. This usually \n",
+              File->filename);
+      mprintf("         indicates a corrupted trajectory. Will attempt to read %i frames.\n",
+              Frames);
+      seekable=false;
+    }
   }
+  stop = Frames;
 
   if (debug>0)
     rprintf("Atoms: %i FrameSize: %i TitleSize: %i NumBox: %i Seekable: %i Frames: %i\n\n", 
@@ -315,7 +376,9 @@
   frameSize += hasREMD;
 
   // If box coords are present, allocate extra space for them
-  if (isBox>0) {
+  // NOTE: Currently only writing box lengths for all box types. This means
+  //       writing triclinic box type is currently not supported.
+  if (BoxType!=0) {
     numBoxCoords=3; // Only write out box lengths for trajectories
     frameSize+=((numBoxCoords*8)+1);
   }
diff -urN amber11.orig/AmberTools/src/cpptraj/src/ArgList.cpp amber11/AmberTools/src/cpptraj/src/ArgList.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/ArgList.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/ArgList.cpp	2011-10-25 15:01:28.101288648 +0300
@@ -146,8 +146,16 @@
   return argline;
 }
 
-/*
- * ArgList::Command()
+/* ArgList::Arg()
+ * Return arg at specified position.
+ */
+char *ArgList::Arg(int pos) {
+  if (pos>-1 && pos<nargs) 
+    return arglist[pos];
+  return NULL;
+}
+
+/* ArgList::Command()
  * Check the first arg for command
  * Mark and return. Return even if marked.
  */
diff -urN amber11.orig/AmberTools/src/cpptraj/src/ArgList.h amber11/AmberTools/src/cpptraj/src/ArgList.h
--- amber11.orig/AmberTools/src/cpptraj/src/ArgList.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/ArgList.h	2011-10-25 15:01:28.102288647 +0300
@@ -15,6 +15,7 @@
     void Add(char *);
     void print();
     char *ArgLine();
+    char *Arg(int);
 
     char *Command();
     int CommandIs(const char *);
diff -urN amber11.orig/AmberTools/src/cpptraj/src/AtomMap.cpp amber11/AmberTools/src/cpptraj/src/AtomMap.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/AtomMap.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/AtomMap.cpp	2011-10-25 15:01:28.081288667 +0300
@@ -6,6 +6,7 @@
 #include "TorsionRoutines.h"
 // DEBUG
 #include "Mol2File.h"
+#include <cstdio>
 
 //--------- PRIVATE ROUTINES ---------------------------------------
 /*
@@ -463,21 +464,27 @@
 // Write atommap out as a mol2 file, useful for checking bond info
 void atommap::WriteMol2(char *m2filename) {
   Mol2File outfile;
-  int *Selected;
+  AtomMask M1;
   // Temporary parm to play with
   AmberParm *tmpParm;
+  Frame *tmpFrame;
 
   // Create mask containing all atoms
-  Selected = (int*) malloc(natom*sizeof(int));
-  for (int atom=0; atom<natom; atom++) Selected[atom]=atom;
+  //for (int atom=0; atom<natom; atom++) Selected[atom]=atom;
   // Fake strip, just use as crap way to copy
-  tmpParm = P->modifyStateByMask(Selected,natom);
-  free(Selected);
+  //tmpParm = P->modifyStateByMask(Selected,natom);
+  //free(Selected);
   // Modify the bonds array to include this info
-  tmpParm->ResetBondInfo();
-  for (int atom=0; atom<natom; atom++) 
-    for (int bond=0; bond < M[atom].nbond; bond++) 
-      tmpParm->AddBond(atom, M[atom].bond[bond], 0);
+  //tmpParm->ResetBondInfo();
+  //for (int atom=0; atom<natom; atom++) 
+  //  for (int bond=0; bond < M[atom].nbond; bond++) 
+  //    tmpParm->AddBond(atom, M[atom].bond[bond], 0);
+  // Create mask with all mapped atoms
+  for (int atom=0; atom<natom; atom++) {if (M[atom].isMapped) M1.AddAtom(atom);}
+  // Strip so only mapped atoms remain
+  tmpParm = P->modifyStateByMask(M1.Selected,M1.Nselected);
+  tmpFrame = new Frame(M1.Nselected,NULL);
+  tmpFrame->SetFrameFromMask(F, &M1);
 
   // Trajectory Setup
   outfile.File=new PtrajFile();
@@ -485,13 +492,14 @@
   outfile.trajfilename = outfile.File->basefilename;
   outfile.debug=debug;
   outfile.SetTitle(m2filename);
-  outfile.P=P;
+  outfile.P=tmpParm;
   outfile.SetupWrite();
   outfile.open();
-  outfile.F=F;
+  outfile.F=tmpFrame;
   outfile.writeFrame(0);
   outfile.close();
   delete tmpParm;
+  delete tmpFrame;
 }
 // ============================================================================
 
@@ -1032,6 +1040,13 @@
   int iterations=0;
 
   numAtomsMapped=MapUniqueAtoms(Ref, Tgt);
+  // DEBUG
+  //char name[1024];
+  //sprintf(name,"Ref.%i.mol2",iterations);
+  //Ref->WriteMol2(name);
+  //sprintf(name,"Tgt.%i.mol2",iterations);
+  //Tgt->WriteMol2(name);
+  // END DEBUG
   if (debug>0)
     mprintf("*         MapUniqueAtoms: %i atoms mapped.\n",numAtomsMapped);
   if (numAtomsMapped==0) return 1;
@@ -1045,17 +1060,35 @@
     iterations++;
     // First assign based on bonds to unique (already mapped) atoms.
     numAtomsMapped=mapBondsToUnique(Ref,Tgt);
+    // DEBUG
+    //sprintf(name,"Ref.%i.u.mol2",iterations);
+    //Ref->WriteMol2(name);
+    //sprintf(name,"Tgt.%i.u.mol2",iterations);
+    //Tgt->WriteMol2(name);
+    // END DEBUG
     if (debug>0)
       mprintf("* [%3i] mapBondsToUnique: %i atoms mapped.\n",iterations,numAtomsMapped);
     if (numAtomsMapped<0) return 1;
     // Next assign based on chirality
     numAtomsMapped=mapChiral(Ref,Tgt);
+    // DEBUG
+    //sprintf(name,"Ref.%i.c.mol2",iterations);
+    //Ref->WriteMol2(name);
+    //sprintf(name,"Tgt.%i.c.mol2",iterations);
+    //Tgt->WriteMol2(name);
+    // END DEBUG
     if (debug>0)
       mprintf("* [%3i]        mapChiral: %i atoms mapped.\n",iterations,numAtomsMapped);
     if (numAtomsMapped<0) return 1;
     if (numAtomsMapped>0) continue;
     // Last assign based on index/element
     numAtomsMapped=mapByIndex(Ref,Tgt);
+    // DEBUG
+    //sprintf(name,"Ref.%i.i.mol2",iterations);
+    //Ref->WriteMol2(name);
+    //sprintf(name,"Tgt.%i.i.mol2",iterations);
+    //Tgt->WriteMol2(name);
+    // END DEBUG
     if (debug>0)
       mprintf("* [%3i]       mapByIndex: %i atoms mapped.\n",iterations,numAtomsMapped);
     if (numAtomsMapped<0) return 1;
diff -urN amber11.orig/AmberTools/src/cpptraj/src/CoordFileList.cpp amber11/AmberTools/src/cpptraj/src/CoordFileList.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/CoordFileList.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/CoordFileList.cpp	2011-10-25 15:01:28.201288557 +0300
@@ -1,4 +1,5 @@
 // CoordFileList
+#include <cstddef>
 #include <cstring> // strcmp
 #include "CoordFileList.h"
 #include "CpptrajStdio.h"
diff -urN amber11.orig/AmberTools/src/cpptraj/src/cpptrajdepend amber11/AmberTools/src/cpptraj/src/cpptrajdepend
--- amber11.orig/AmberTools/src/cpptraj/src/cpptrajdepend	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/cpptrajdepend	2011-10-25 15:01:28.107288643 +0300
@@ -2,7 +2,7 @@
 AmberNetcdf.o : AmberNetcdf.cpp AmberNetcdf.h AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CpptrajStdio.h Frame.h NetcdfRoutines.h PtrajFile.h Range.h TrajFile.h
 AmberParm.o : AmberParm.cpp AmberParm.h BaseFileIO.h CpptrajStdio.h Mol2FileRoutines.h PDBfileRoutines.h PtrajFile.h
 AmberTraj.o : AmberTraj.cpp AmberParm.h AmberTraj.h ArgList.h AtomMask.h BaseFileIO.h CpptrajStdio.h Frame.h PtrajFile.h Range.h TrajFile.h
-TrajFile.o : TrajFile.cpp AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CpptrajStdio.h Frame.h PtrajFile.h PtrajMpi.h Range.h TrajFile.h
+TrajFile.o : TrajFile.cpp AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CpptrajStdio.h Frame.h PtrajFile.h Range.h TrajFile.h
 Frame.o : Frame.cpp AmberParm.h AtomMask.h BaseFileIO.h CpptrajStdio.h DistRoutines.h Frame.h PtrajFile.h TorsionRoutines.h vectormath.h
 PtrajState.o : PtrajState.cpp Action.h AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CoordFileList.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h Frame.h FrameList.h ParmFileList.h PtrajActionList.h PtrajFile.h PtrajMpi.h PtrajState.h Range.h ReferenceList.h TrajFile.h TrajinList.h TrajoutList.h
 ArgList.o : ArgList.cpp ArgList.h CpptrajStdio.h
@@ -13,7 +13,7 @@
 TrajoutList.o : TrajoutList.cpp AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CoordFileList.h CpptrajStdio.h Frame.h ParmFileList.h PtrajFile.h Range.h TrajFile.h TrajoutList.h
 ReferenceList.o : ReferenceList.cpp AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CoordFileList.h CpptrajStdio.h Frame.h FrameList.h ParmFileList.h PtrajFile.h Range.h ReferenceList.h TrajFile.h
 CoordFileList.o : CoordFileList.cpp AmberNetcdf.h AmberParm.h AmberRestart.h AmberRestartNC.h AmberTraj.h ArgList.h AtomMask.h BaseFileIO.h Conflib.h CoordFileList.h CpptrajStdio.h Frame.h Mol2File.h PDBfile.h ParmFileList.h PtrajFile.h Range.h RemdTraj.h TrajFile.h TrajinList.h
-PtrajActionList.o : PtrajActionList.cpp Action.h Action_Angle.h Action_Center.h Action_Closest.h Action_DSSP.h Action_Dihedral.h Action_Distance.h Action_Hbond.h Action_Image.h Action_Mask.h Action_NAstruct.h Action_Outtraj.h Action_Pucker.h Action_Radgyr.h Action_Rmsd.h Action_Strip.h Action_Surf.h AmberParm.h ArgList.h AtomMap.h AtomMask.h AxisType.h BaseFileIO.h CoordFileList.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h Frame.h FrameList.h ParmFileList.h PtrajActionList.h PtrajFile.h Range.h TrajFile.h TrajoutList.h
+PtrajActionList.o : PtrajActionList.cpp Action.h Action_Angle.h Action_Center.h Action_Closest.h Action_DSSP.h Action_Dihedral.h Action_Distance.h Action_Hbond.h Action_Image.h Action_Mask.h Action_NAstruct.h Action_Outtraj.h Action_Pucker.h Action_Radgyr.h Action_Rms2d.h Action_Rmsd.h Action_Strip.h Action_Surf.h AmberParm.h ArgList.h AtomMap.h AtomMask.h AxisType.h BaseFileIO.h CoordFileList.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h Frame.h FrameList.h ParmFileList.h PtrajActionList.h PtrajFile.h Range.h TrajFile.h TrajoutList.h
 DataSet.o : DataSet.cpp CpptrajStdio.h DataSet.h
 DataSetList.o : DataSetList.cpp CpptrajStdio.h DataSet.h DataSetList.h intDataSet.h mapDataSet.h stringDataSet.h
 vectormath.o : vectormath.cpp CpptrajStdio.h vectormath.h
@@ -23,9 +23,9 @@
 DataFile.o : DataFile.cpp BaseFileIO.h CpptrajStdio.h DataFile.h DataSet.h PtrajFile.h
 DataFileList.o : DataFileList.cpp BaseFileIO.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h PtrajFile.h
 PDBfile.o : PDBfile.cpp AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CpptrajStdio.h Frame.h PDBfile.h PDBfileRoutines.h PtrajFile.h Range.h TrajFile.h
-PtrajFile.o : PtrajFile.cpp BaseFileIO.h Bzip2File.h CpptrajStdio.h GzipFile.h MpiFile.h NetcdfRoutines.h PDBfileRoutines.h PtrajFile.h PtrajMpi.h StdFile.h
+PtrajFile.o : PtrajFile.cpp BaseFileIO.h Bzip2File.h CpptrajStdio.h GzipFile.h Mol2FileRoutines.h MpiFile.h NetcdfRoutines.h PDBfileRoutines.h PtrajFile.h PtrajMpi.h StdFile.h
 PDBfileRoutines.o : PDBfileRoutines.cpp PDBfileRoutines.h
-AtomMap.o : AtomMap.cpp Action.h AmberParm.h ArgList.h AtomMap.h AtomMask.h BaseFileIO.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h Frame.h FrameList.h PDBfileRoutines.h ParmFileList.h PtrajFile.h TorsionRoutines.h
+AtomMap.o : AtomMap.cpp Action.h AmberParm.h ArgList.h AtomMap.h AtomMask.h BaseFileIO.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h Frame.h FrameList.h Mol2File.h ParmFileList.h PtrajFile.h Range.h TorsionRoutines.h TrajFile.h
 BaseFileIO.o : BaseFileIO.cpp BaseFileIO.h PtrajMpi.h
 StdFile.o : StdFile.cpp BaseFileIO.h StdFile.h
 GzipFile.o : GzipFile.cpp BaseFileIO.h CpptrajStdio.h GzipFile.h
@@ -62,3 +62,4 @@
 Action_Pucker.o : Action_Pucker.cpp Action.h Action_Pucker.h AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h Frame.h FrameList.h ParmFileList.h PtrajFile.h
 Range.o : Range.cpp ArgList.h CpptrajStdio.h Range.h
 Action_Outtraj.o : Action_Outtraj.cpp Action.h Action_Outtraj.h AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CoordFileList.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h Frame.h FrameList.h ParmFileList.h PtrajFile.h PtrajMpi.h Range.h TrajFile.h TrajoutList.h
+Action_Rms2d.o : Action_Rms2d.cpp Action.h Action_Rms2d.h AmberParm.h ArgList.h AtomMask.h BaseFileIO.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h Frame.h FrameList.h ParmFileList.h PtrajFile.h
diff -urN amber11.orig/AmberTools/src/cpptraj/src/DataFile.cpp amber11/AmberTools/src/cpptraj/src/DataFile.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/DataFile.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/DataFile.cpp	2011-10-25 15:01:28.098288651 +0300
@@ -65,8 +65,49 @@
   isInverted=true;
 }
 
-/*
- * DataFile::AddSet()
+/* DataFile::SetPrecision()
+ * Set precision of the specified dataset to width.precision. If '*' specified 
+ * set for all datasets in file.
+ */
+void DataFile::SetPrecision(char *dsetName, int widthIn, int precisionIn) {
+  int precision, dset;
+  DataSet *Dset = NULL;
+
+  if (dsetName==NULL) {
+    mprintf("Error: SetPrecision must be called with dataset name or '*'.\n");
+    return;
+  }
+  if (widthIn<1) {
+    mprintf("Error: SetPrecision (%s): Cannot set width < 1.\n",filename);
+    return;
+  }
+  precision=precisionIn;
+  if (precisionIn<0) precision=0;
+  // If <dsetName>=='*' specified set precision for all data sets
+  if (dsetName[0]=='*') {
+    mprintf("    Setting width.precision for all sets in %s to %i.%i\n",
+            filename,widthIn,precision);
+    for (dset=0; dset<Nsets; dset++)
+      SetList[dset]->SetPrecision(widthIn,precision);
+
+  // Otherwise find dataset <dsetName> and set precision
+  } else {
+    mprintf("    Setting width.precision for dataset %s to %i.%i\n",
+            dsetName,widthIn,precision);
+    for (dset=0; dset<Nsets; dset++) {
+      if ( strcmp(SetList[dset]->Name(), dsetName)==0 ) {
+        Dset=SetList[dset];
+        break;
+      }
+    }
+    if (Dset!=NULL)
+      Dset->SetPrecision(widthIn,precision);
+    else
+      mprintf("Error: Dataset %s not found in datafile %s\n",dsetName,filename);
+  }
+}
+
+/* DataFile::AddSet()
  * Add given set to this datafile
  */
 int DataFile::AddSet(DataSet *D) {
diff -urN amber11.orig/AmberTools/src/cpptraj/src/DataFile.h amber11/AmberTools/src/cpptraj/src/DataFile.h
--- amber11.orig/AmberTools/src/cpptraj/src/DataFile.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/DataFile.h	2011-10-25 15:01:28.098288651 +0300
@@ -30,6 +30,7 @@
     void SetXlabel(char*);
     void SetInverted();
     void SetNoXcol();
+    void SetPrecision(char *, int, int);
     int AddSet(DataSet *);
     int NameIs(char *);
     void DataSetNames();
diff -urN amber11.orig/AmberTools/src/cpptraj/src/DataFileList.cpp amber11/AmberTools/src/cpptraj/src/DataFileList.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/DataFileList.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/DataFileList.cpp	2011-10-25 15:01:28.201288557 +0300
@@ -1,4 +1,5 @@
 // DataFileList
+#include <cstddef>
 #include "DataFileList.h"
 #include "CpptrajStdio.h"
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/DataSet.cpp amber11/AmberTools/src/cpptraj/src/DataSet.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/DataSet.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/DataSet.cpp	2011-10-25 15:01:28.094288655 +0300
@@ -1,6 +1,7 @@
 // DataSet
 #include <cstdlib>
 #include <cstring>
+#include <cstdio> // sprintf
 #include "DataSet.h"
 #include "CpptrajStdio.h"
 
@@ -11,12 +12,73 @@
   N=0;
   isDynamic=false;
   current=0;
+  width = 0;
+  precision = 0;
+  format = NULL;
+  dType = UNKNOWN_DATA;
 }
 
 // DESTRUCTOR
 DataSet::~DataSet() {
   //fprintf(stderr,"DataSet Destructor\n");
   if (name!=NULL) free(name);
+  if (format!=NULL) free(format);
+}
+
+/*
+ * DataSet::setFormatString()
+ * Set up the output format string for each data element based on the given 
+ * dataType and the current width, and precision.
+ */
+void DataSet::setFormatString() {
+  size_t stringWidth = 0;
+  int wWidth = 0;
+  int pWidth = 0;
+
+  if (format!=NULL) {free(format); format=NULL;}
+
+  // Calc num of chars necessary to hold width
+  wWidth = (width / 10) + 1;
+
+  switch (dType) {
+    case DOUBLE :
+      // Calc num of chars necessary to hold precision
+      pWidth = (precision / 10) + 1;
+      // String fmt: " %w.plf\0"
+      stringWidth = pWidth + wWidth + 6;
+      format = (char*) malloc( stringWidth * sizeof(char) );
+      sprintf(format, " %%%i.%ilf", width, precision);
+      break;
+    case STRING :
+      // String fmt: " %s"
+      format = (char*) malloc( 4 * sizeof(char) );
+      strcpy(format, " %s");
+      break;
+    case INT :
+      // String fmt: " %wi"
+      stringWidth = wWidth + 4;
+      format = (char*) malloc( stringWidth * sizeof(char) );
+      sprintf(format, " %%%ii", width);
+      break;
+    case UNKNOWN_DATA :
+      mprintf("Internal Error: setFormatString called with unknown data type.\n");
+  }
+
+  if (format==NULL) 
+    mprintf("Error: setFormatString: Could not allocate memory for string.\n");
+  // DEBUG
+  //else
+  //  mprintf("DEBUG: Format string: [%s]\n",format);
+}    
+
+/*
+ * DataSet::SetPrecision()
+ * Set dataset width and precision and recalc output format string.
+ */
+void DataSet::SetPrecision(int widthIn, int precisionIn) {
+  width=widthIn;
+  precision=precisionIn;
+  setFormatString();
 }
 
 /* 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/DataSet.h amber11/AmberTools/src/cpptraj/src/DataSet.h
--- amber11.orig/AmberTools/src/cpptraj/src/DataSet.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/DataSet.h	2011-10-25 15:01:28.103288646 +0300
@@ -36,12 +36,18 @@
 class DataSet {
   protected:
     char *name;        // Name of the dataset
+    dataType dType;    // The dataset type
     int N;             // Number of data elements
     int current;       // The current data element
+    int width;         // The output width of a data element
+    int precision;     // The output precision of a data element (if applicable)
+    char *format;      // Format of output
+    
     bool isDynamic;    // True : N is not known, reallocate as N increases
                        // False: N is known, allocate for N
     // If not isDynamic, Allocate will reserve space for N data elements 
     virtual int Allocate( )      { return 0; }
+    void setFormatString();
 
   public:
 
@@ -51,13 +57,16 @@
     virtual int Xmax()               { return 0; }
     virtual int isEmpty(int)         { return 0; }
     virtual void Add( int, void * )  { return;   }
+    virtual int Get( void *, int )   { return 1; }
     virtual char *Write(char*, int)  { return 0; }
     virtual int Width()              { return 0; }
     virtual int Sync()               { return 0; }
 
+    void SetPrecision(int,int);
     int Setup(char*,int);
     void Info();
     char *Name() { return name; }
     int CheckSet();
+    dataType Type() {return dType;}
 };
 #endif 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Frame.cpp amber11/AmberTools/src/cpptraj/src/Frame.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Frame.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Frame.cpp	2011-10-25 15:01:28.120288631 +0300
@@ -60,8 +60,38 @@
   if (Mass!=NULL) free(Mass);
 }
 
-/*
- * Frame::Copy()
+/* Frame::ZeroCoords()
+ * Set all coords to 0.0
+ */
+void Frame::ZeroCoords() {
+  for (int coord=0; coord < N; coord++)
+    X[coord]=0.0;
+}
+
+/* Frame::AddCoord()
+ * Add the coord values from the input frame to the coord values of 
+ * this frame.
+ */
+void Frame::AddCoord(Frame *FrameIn) {
+  if (FrameIn->N != this->N) {
+    mprintf("Error: Frame::AddCoord: Attempting to add %i coords to %i coords.\n",
+            FrameIn->N,this->N);
+  } else {
+    for (int coord=0; coord < N; coord++)
+      this->X[coord] += FrameIn->X[coord];
+  }
+}
+
+/* Frame::Divide()
+ * Divide all coord values by input. Dont do it if the number is too small.
+ */
+void Frame::Divide(double divisor) {
+  if (divisor < SMALL) return;
+  for (int coord=0; coord < N; coord++)
+    X[coord] /= divisor;
+}
+
+/* Frame::Copy()
  * Return a copy of the frame
  */
 Frame *Frame::Copy() {
@@ -423,21 +453,21 @@
  * Based on useMassIn, calculate geometric center (false) or center of mass 
  * (true) of the atoms in each mask.
  */
-double Frame::DIST2(AtomMask *Mask1, AtomMask *Mask2, bool useMassIn, int ifbox,
+double Frame::DIST2(AtomMask *Mask1, AtomMask *Mask2, bool useMassIn, int boxType,
                     double *ucell, double *recip) {
   double a1[3], a2[3];
 
   COM(Mask1, a1, useMassIn);
   COM(Mask2, a2, useMassIn);
 
-  if (ifbox == 0) 
+  if (boxType == 0) 
     return DIST2_NoImage(a1, a2);
-  else if (ifbox == 1) 
+  else if (boxType == 1) 
     return DIST2_ImageOrtho(a1, a2, this->box);
-  else if (ifbox == 2) 
+  else if (boxType == 2) 
     return DIST2_ImageNonOrtho(a1, a2, ucell, recip);
 
-  mprintf("    Error: Frame::DIST: Unrecognized box type (%i)\n.", ifbox);
+  mprintf("    Error: Frame::DIST: Unrecognized box type (%i)\n.", boxType);
 
   return (-1.0);
 }
@@ -445,8 +475,11 @@
 /*
  * Frame::DIST2()
  * Return the distance between atoms A1 and A2 with optional imaging.
+ *   0 = None
+ *   1 = Orthorhombic
+ *   2 = Non-orthorhombic
  */
-double Frame::DIST2(int A1, int A2, int ifbox, double *ucell, double *recip) {
+double Frame::DIST2(int A1, int A2, int boxType, double *ucell, double *recip) {
   int atom3;
   double a1[3], a2[3];
 
@@ -459,14 +492,14 @@
   a2[1] = X[atom3+1];
   a2[2] = X[atom3+2];
 
-  if (ifbox == 0)
+  if (boxType == 0)
     return DIST2_NoImage(a1, a2);
-  else if (ifbox == 1)
+  else if (boxType == 1)
     return DIST2_ImageOrtho(a1, a2, this->box);
-  else if (ifbox == 2) 
+  else if (boxType == 2) 
     return DIST2_ImageNonOrtho(a1, a2, ucell, recip);
 
-  mprintf("    Error: Frame::DIST: Unrecognized box type (%i)\n.", ifbox);
+  mprintf("    Error: Frame::DIST: Unrecognized box type (%i)\n.", boxType);
 
   return (-1.0);
 }
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Frame.h amber11/AmberTools/src/cpptraj/src/Frame.h
--- amber11.orig/AmberTools/src/cpptraj/src/Frame.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Frame.h	2011-10-25 15:01:28.092288656 +0300
@@ -22,6 +22,9 @@
     Frame(AtomMask *, double *);
     virtual ~Frame();             // Destructor is virtual since this class can be inherited
 
+    void ZeroCoords();
+    void AddCoord(Frame*);
+    void Divide(double);
     void printAtomCoord(int);
     void GetCoord(double *, int);
     void SetCoord(int, double *);
diff -urN amber11.orig/AmberTools/src/cpptraj/src/FrameList.cpp amber11/AmberTools/src/cpptraj/src/FrameList.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/FrameList.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/FrameList.cpp	2011-10-25 15:01:28.073288675 +0300
@@ -13,7 +13,8 @@
     delete frameList[i];
 }
 
-/* FrameList::Add()
+/* 
+ * FrameList::Add()
  * Add given Frame to the FrameList. Store trajectory name that this frame
  * came from in frameNames. Store the associated parm in FrameParm. 
  */
@@ -29,6 +30,18 @@
   FrameParm.Add(P);
   Nframe++;
   return 0;
+}
+
+/*
+ * FrameList::Add()
+ * Add given Frame to the FrameList. Store the associated parm in FrameParm.
+ */
+int FrameList::Add(Frame *F, AmberParm *P) {
+  if (F==NULL || P==NULL) return 1;
+  frameList.push_back(F);
+  FrameParm.Add(P);
+  Nframe++;
+  return 0;
 }
 
 /* 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/FrameList.h amber11/AmberTools/src/cpptraj/src/FrameList.h
--- amber11.orig/AmberTools/src/cpptraj/src/FrameList.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/FrameList.h	2011-10-25 15:01:28.073288675 +0300
@@ -18,6 +18,7 @@
     ~FrameList();
 
     int Add(Frame *, char *, AmberParm *,int);
+    int Add(Frame *, AmberParm *);
     AmberParm *GetFrameParm(int);
     int GetFrameIndex(char *);
     Frame *GetFrame(int idx);
diff -urN amber11.orig/AmberTools/src/cpptraj/src/GzipFile.cpp amber11/AmberTools/src/cpptraj/src/GzipFile.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/GzipFile.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/GzipFile.cpp	2011-10-25 15:01:28.227288533 +0300
@@ -77,18 +77,24 @@
 
 /*
  * GzipFile::Read()
+ * NOTE: gzread returns 0 on EOF, -1 on error
  */
 int GzipFile::Read(void *buffer, size_t size, size_t count) {
   //size_t numread;
   int numread;
+  int expectedread;
+  
+  expectedread = (int)size;
+  expectedread *= (int)count;
   // Should never be able to call Read when fp is NULL.
   //if (fp==NULL) {
   //  fprintf(stdout,"Error: GzipFile::Read: Attempted to read NULL file pointer.\n");
   //  return 1;
   //}
-  numread = gzread(fp, buffer, size * count);
-  if (numread == -1) return -1;
-
+  numread = gzread(fp, buffer, expectedread);
+  if (numread != expectedread) return -1;
+  //if (numread < 1 ) return -1;
+  
   // NOTE: Check for errors here.
   return numread;
 }
diff -urN amber11.orig/AmberTools/src/cpptraj/src/intDataSet.cpp amber11/AmberTools/src/cpptraj/src/intDataSet.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/intDataSet.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/intDataSet.cpp	2011-10-25 15:01:28.103288646 +0300
@@ -5,6 +5,14 @@
 #include "PtrajMpi.h"
 #include "CpptrajStdio.h"
 using namespace std;
+
+// CONSTRUCTOR
+intDataSet::intDataSet() {
+  width=12;
+  dType=INT;
+  setFormatString();
+}
+
 /*
  * intDataSet::Xmax(()
  * Return the maximum X value added to this set. By convention this is 
@@ -33,8 +41,21 @@
   current++;
 }
 
-/*
- * intDataSet::isEmpty()
+/* intDataSet::Get()
+ * Get data at frame, put into vOut. Return 1 if no data at frame.
+ */
+int intDataSet::Get(void *vOut, int frame) {
+  int *value;
+
+  if (vOut==NULL) return 1;
+  value = (int*) vOut;
+  it=Data.find( frame );
+  if (it == Data.end()) return 1;
+  *value = (*it).second;
+  return 0;
+}
+
+/* intDataSet::isEmpty()
  */
 int intDataSet::isEmpty(int frame) {
   it = Data.find( frame );
@@ -52,17 +73,17 @@
   it = Data.find( frame );
   if (it == Data.end()) 
     //sprintf(buffer," %12s","NoData");
-    sprintf(buffer," %12i", 0);
+    sprintf(buffer, format, 0);
   else 
-    sprintf(buffer," %12i",(*it).second);
-  return (buffer + 13);
+    sprintf(buffer, format, (*it).second);
+  return (buffer + width + 1);
 }
 
 /*
  * intDataSet::Width()
  */
 int intDataSet::Width() {
-  return 13;
+  return (width + 1);
 }
 
 /*
diff -urN amber11.orig/AmberTools/src/cpptraj/src/intDataSet.h amber11/AmberTools/src/cpptraj/src/intDataSet.h
--- amber11.orig/AmberTools/src/cpptraj/src/intDataSet.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/intDataSet.h	2011-10-25 15:01:28.104288645 +0300
@@ -11,9 +11,12 @@
     std::map<int,int> Data;
     std::map<int,int>::iterator it;
   public:
+    intDataSet();
+
     int Xmax();
     int isEmpty(int);
     void Add( int, void * );
+    int Get(void *, int);
     char *Write(char *, int);
     int Width();
     int Sync();
diff -urN amber11.orig/AmberTools/src/cpptraj/src/main.cpp amber11/AmberTools/src/cpptraj/src/main.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/main.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/main.cpp	2011-10-25 15:01:28.228288532 +0300
@@ -6,7 +6,7 @@
 #include "PtrajMpi.h"
 #include "CpptrajStdio.h"
 #ifndef CPPTRAJ_VERSION_STRING
-#define CPPTRAJ_VERSION_STRING "V1.0.5"
+#define CPPTRAJ_VERSION_STRING "V1.1.1"
 #endif
 
 void Usage(char *programName) {
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Makefile amber11/AmberTools/src/cpptraj/src/Makefile
--- amber11.orig/AmberTools/src/cpptraj/src/Makefile	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Makefile	2011-10-25 15:01:28.075288673 +0300
@@ -16,7 +16,8 @@
        Action_Radgyr.cpp Conflib.cpp Action_Mask.cpp Action_Closest.cpp \
        NetcdfRoutines.cpp AmberRestartNC.cpp CpptrajStdio.cpp Mol2File.cpp \
        Mol2FileRoutines.cpp Action_NAstruct.cpp DistRoutines.cpp AxisType.cpp \
-       TorsionRoutines.cpp Action_Pucker.cpp Range.cpp Action_Outtraj.cpp
+       TorsionRoutines.cpp Action_Pucker.cpp Range.cpp Action_Outtraj.cpp \
+       Action_Rms2d.cpp
 
 OBJECTS=main.o AmberNetcdf.o AmberParm.o AmberTraj.o TrajFile.o \
         Frame.o PtrajState.o ArgList.o ptrajmask.o Action_Distance.o \
@@ -32,7 +33,8 @@
         Action_Radgyr.o Conflib.o Action_Mask.o Action_Closest.o \
         NetcdfRoutines.o AmberRestartNC.o CpptrajStdio.o Mol2File.o \
         Mol2FileRoutines.o Action_NAstruct.o DistRoutines.o AxisType.o \
-        TorsionRoutines.o Action_Pucker.o Range.o Action_Outtraj.o
+        TorsionRoutines.o Action_Pucker.o Range.o Action_Outtraj.o \
+        Action_Rms2d.o
 
 HEADERS=AmberNetcdf.h AmberParm.h AmberTraj.h TrajFile.h \
         Frame.h PtrajState.h ArgList.h ptrajmask.h Action.h Action_Distance.h \
@@ -48,7 +50,8 @@
         Action_Radgyr.h Conflib.h Action_Mask.h Action_Closest.h \
         NetcdfRoutines.h AmberRestartNC.h CpptrajStdio.h Mol2File.h \
         Mol2FileRoutines.h Action_NAstruct.h DistRoutines.h AxisType.h \
-        TorsionRoutines.h Action_Pucker.h Range.h Action_Outtraj.h
+        TorsionRoutines.h Action_Pucker.h Range.h Action_Outtraj.h \
+        Action_Rms2d.h
 
 all: cpptraj$(SFX)
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Makefile_at amber11/AmberTools/src/cpptraj/src/Makefile_at
--- amber11.orig/AmberTools/src/cpptraj/src/Makefile_at	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Makefile_at	2011-10-25 15:01:28.076288672 +0300
@@ -16,7 +16,8 @@
        Action_Radgyr.cpp Conflib.cpp Action_Mask.cpp Action_Closest.cpp \
        NetcdfRoutines.cpp AmberRestartNC.cpp CpptrajStdio.cpp Mol2File.cpp \
        Mol2FileRoutines.cpp Action_NAstruct.cpp DistRoutines.cpp AxisType.cpp \
-       TorsionRoutines.cpp Action_Pucker.cpp Range.cpp Action_Outtraj.cpp
+       TorsionRoutines.cpp Action_Pucker.cpp Range.cpp Action_Outtraj.cpp \
+       Action_Rms2d.cpp
 
 OBJECTS=main.o AmberNetcdf.o AmberParm.o AmberTraj.o TrajFile.o \
         Frame.o PtrajState.o ArgList.o ptrajmask.o Action_Distance.o \
@@ -32,7 +33,8 @@
         Action_Radgyr.o Conflib.o Action_Mask.o Action_Closest.o \
         NetcdfRoutines.o AmberRestartNC.o CpptrajStdio.o Mol2File.o \
         Mol2FileRoutines.o Action_NAstruct.o DistRoutines.o AxisType.o \
-        TorsionRoutines.o Action_Pucker.o Range.o Action_Outtraj.o
+        TorsionRoutines.o Action_Pucker.o Range.o Action_Outtraj.o \
+        Action_Rms2d.o
 
 HEADERS=AmberNetcdf.h AmberParm.h AmberTraj.h TrajFile.h \
         Frame.h PtrajState.h ArgList.h ptrajmask.h Action.h Action_Distance.h \
@@ -48,7 +50,8 @@
         Action_Radgyr.h Conflib.h Action_Mask.h Action_Closest.h \
         NetcdfRoutines.h AmberRestartNC.h CpptrajStdio.h Mol2File.h \
         Mol2FileRoutines.h Action_NAstruct.h DistRoutines.h AxisType.h \
-        TorsionRoutines.h Action_Pucker.h Range.h Action_Outtraj.h
+        TorsionRoutines.h Action_Pucker.h Range.h Action_Outtraj.h \
+        Action_Rms2d.h
 
 all: cpptraj$(SFX)
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/mapDataSet.cpp amber11/AmberTools/src/cpptraj/src/mapDataSet.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/mapDataSet.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/mapDataSet.cpp	2011-10-25 15:01:28.104288645 +0300
@@ -6,6 +6,14 @@
 #include "CpptrajStdio.h"
 using namespace std;
 
+// CONSTRUCTOR
+mapDataSet::mapDataSet() {
+  width = 12;
+  precision = 4;
+  dType=DOUBLE;
+  setFormatString();
+}
+
 /*
  * mapDataSet::Xmax(()
  * Return the maximum X value added to this set. By convention this is 
@@ -34,8 +42,23 @@
   current++;
 }
 
-/*
- * mapDataSet::isEmpty()
+/* mapDataSet::Get()
+ * Get data at frame, put into vOut. Return 1 if no data at frame.
+ */
+int mapDataSet::Get(void *vOut, int frame) {
+  double *value;
+  
+  if (vOut==NULL) return 1;
+  //mprintf("DEBUG: Attempting to get double frame %i\n",frame);
+  value = (double*) vOut;
+  it=Data.find( frame );
+  if (it == Data.end()) return 1;
+  //mprintf("DEBUG: Double frame %i is %lf\n",frame,(*it).second);
+  *value = (*it).second;
+  return 0;
+}
+
+/* mapDataSet::isEmpty()
  */
 int mapDataSet::isEmpty(int frame) {
   it = Data.find( frame );
@@ -53,17 +76,17 @@
   it = Data.find( frame );
   if (it == Data.end()) 
     //sprintf(buffer," %12s","NoData");
-    sprintf(buffer," %12.4lf", 0.0);
+    sprintf(buffer, format, 0.0);
   else 
-    sprintf(buffer," %12.4lf",(*it).second);
-  return (buffer + 13);
+    sprintf(buffer, format,(*it).second);
+  return (buffer + width + 1);
 }
 
 /*
  * mapDataSet::Width()
  */
 int mapDataSet::Width() {
-  return 13;
+  return (width + 1);
 }
 
 /*
diff -urN amber11.orig/AmberTools/src/cpptraj/src/mapDataSet.h amber11/AmberTools/src/cpptraj/src/mapDataSet.h
--- amber11.orig/AmberTools/src/cpptraj/src/mapDataSet.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/mapDataSet.h	2011-10-25 15:01:28.105288645 +0300
@@ -7,14 +7,16 @@
  */
 #include <map>
 #include "DataSet.h"
-//using namespace std;
 class mapDataSet : public DataSet {
     std::map<int,double> Data;
     std::map<int,double>::iterator it;
   public:
+    mapDataSet();
+
     int Xmax();
     int isEmpty(int);
     void Add( int, void * );
+    int Get(void *, int);
     char *Write(char *, int);
     int Width();
     int Sync();
diff -urN amber11.orig/AmberTools/src/cpptraj/src/Mol2File.cpp amber11/AmberTools/src/cpptraj/src/Mol2File.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/Mol2File.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/Mol2File.cpp	2011-10-25 15:01:28.127288624 +0300
@@ -239,6 +239,8 @@
   if (writeMode==2)
     File->IO->Close();
 
+  currentFrame++;
+
   return 0;
 }
  
diff -urN amber11.orig/AmberTools/src/cpptraj/src/PDBfile.cpp amber11/AmberTools/src/cpptraj/src/PDBfile.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/PDBfile.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/PDBfile.cpp	2011-10-25 15:01:28.128288623 +0300
@@ -207,6 +207,9 @@
   } else if (writeMode==1) {
     File->IO->Printf("ENDMDL\n");
   }
+
+  currentFrame++;
+
   return 0;
 }
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/PtrajActionList.cpp amber11/AmberTools/src/cpptraj/src/PtrajActionList.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/PtrajActionList.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/PtrajActionList.cpp	2011-10-25 15:01:28.105288645 +0300
@@ -20,6 +20,7 @@
 #include "Action_NAstruct.h"
 #include "Action_Pucker.h"
 #include "Action_Outtraj.h"
+#include "Action_Rms2d.h"
 
 // Constructor
 PtrajActionList::PtrajActionList() {
@@ -56,6 +57,7 @@
 
   // Decide what action this is based on the command.
   if      (A->CommandIs("distance")) {Act=new Distance;}
+  else if (A->CommandIs("rms2d"))    {Act=new Rms2d;   }
   else if (A->CommandIs("rmsd",3))   {Act=new Rmsd;    }
   else if (A->CommandIs("dihedral")) {Act=new Dihedral;}
   else if (A->CommandIs("atommap"))  {Act=new AtomMap; }
@@ -166,6 +168,8 @@
     err = ActionList[act]->DoAction(FrameAddress, frameIn);
     if (err==1) {
       // Treat actions that fail as if they could not be set up
+      mprintf("Warning: Action [%s] failed, frame %i.\n",ActionList[act]->CmdLine(),
+              frameIn);
       ActionList[act]->noSetup=1;
     } else if (err==2) {
       // Return value of 2 requests return to original frame
diff -urN amber11.orig/AmberTools/src/cpptraj/src/PtrajFile.cpp amber11/AmberTools/src/cpptraj/src/PtrajFile.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/PtrajFile.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/PtrajFile.cpp	2011-10-25 15:01:28.196288560 +0300
@@ -113,6 +113,7 @@
 void PtrajFile::CloseFile() {
   if (isOpen) {
     IO->Close();
+    if (debug>0) rprintf("Closed %s.\n",filename);
     isOpen=0;
   }
 }
@@ -417,8 +418,8 @@
   // Standard file size is in the frame_stat struct
   uncompressed_size = IO->Size(filename);
 
-  // Determine format
-  // Read first 3 bytes again to determine format by magic number
+  // ========== Determine format ==========
+  // ---------- Read first 3 bytes again to determine format by magic number ----------
   IO->Open(filename,"rb"); // NOTE: Err Check
   memset(magic,0,3*sizeof(unsigned char));
   IO->Read(magic  ,1,1);
@@ -454,7 +455,7 @@
     return 0;
   }
 
-  // ID by file characteristics; read the first two lines
+  // ---------- ID by file characteristics; read the first two lines ----------
   // Initialize buffers to NULL
   buffer1[0]='\0';
   buffer2[0]='\0';
@@ -472,17 +473,6 @@
     }
   }
 
-  // Reopen and scan for Tripos mol2 molecule section
-  // 0 indicates section found.
-  IO->Open(filename,"r");
-  if (!Mol2ScanTo(this, MOLECULE)) {
-    if (debug>0) mprintf("  TRIPOS MOL2 file\n");
-    fileFormat=MOL2FILE;
-    IO->Close();
-    return 0;
-  }
-  IO->Close();
-
   // If both lines have PDB keywords, assume PDB
   if (isPDBkeyword(buffer1) && isPDBkeyword(buffer2)) {
     if (debug>0) mprintf("  PDB file\n");
@@ -491,7 +481,8 @@
   }
 
   // If either buffer contains a TRIPOS keyword assume Mol2
-  // NOTE: This will fail on tripos files with extensive header comments
+  // NOTE: This will fail on tripos files with extensive header comments.
+  //       A more expensive check for mol2 files is below.
   if (strncmp(buffer1,"@<TRIPOS>", 9)==0 ||
       strncmp(buffer2,"@<TRIPOS>", 9)==0) {
     if (debug>0) mprintf("  TRIPOS MOL2 file\n");
@@ -547,7 +538,19 @@
     }
   }
 
-  // NOTE: EXPERIMENTAL
+  // ---------- MORE EXPENSIVE CHECKS ----------
+  // Reopen and scan for Tripos mol2 molecule section
+  // 0 indicates section found.
+  IO->Open(filename,"r");
+  if (!Mol2ScanTo(this, MOLECULE)) {
+    if (debug>0) mprintf("  TRIPOS MOL2 file\n");
+    fileFormat=MOL2FILE;
+    IO->Close();
+    return 0;
+  }
+  IO->Close();
+
+  // ---------- EXPERIMENTAL ----------
   // If the file format is still undetermined and the file name is conflib.dat,
   // assume this is a conflib.dat file from LMOD. Cant think of a better way to
   // detect this since there is no magic number but the file is binary.
diff -urN amber11.orig/AmberTools/src/cpptraj/src/PtrajMpi.c amber11/AmberTools/src/cpptraj/src/PtrajMpi.c
--- amber11.orig/AmberTools/src/cpptraj/src/PtrajMpi.c	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/PtrajMpi.c	2011-10-25 15:01:28.100288649 +0300
@@ -460,7 +460,10 @@
   }
 
   err = MPI_Allreduce(input, Return, count, currentType, currentOp, MPI_COMM_WORLD);
-  if (err!=MPI_SUCCESS) printMPIerr(err, "Performing allreduce for %i elements\n",count);
+  if (err!=MPI_SUCCESS) {
+    printMPIerr(err, "Performing allreduce.\n");
+    rprintf("Error: allreduce failed for %i elements.\n",count);
+  }
 
   if (parallel_check_error(err)!=0) return 1;
   return 0;
diff -urN amber11.orig/AmberTools/src/cpptraj/src/PtrajState.cpp amber11/AmberTools/src/cpptraj/src/PtrajState.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/PtrajState.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/PtrajState.cpp	2011-10-25 15:01:28.214288545 +0300
@@ -7,7 +7,8 @@
 #include "CpptrajStdio.h"
 
 // Constructor
-PtrajState::PtrajState() { 
+PtrajState::PtrajState() {
+  TotalErrors=0; 
   debug=0;
   showProgress=1;
 }
@@ -291,6 +292,7 @@
   char *df_cmd = NULL;
   char *name1 = NULL;
   char *name2 = NULL;
+  int width,precision;
   DataFile *df;
 
   if (DF_Args.empty()) return;
@@ -349,6 +351,19 @@
       }
       mprintf("    Not printing x column for datafile %s\n",name1);
       df->SetNoXcol();
+    
+    // datafile precision
+    // Usage: datafile precision <filename> <dataset> [<width>] [<precision>]
+    //        If width/precision not specified default to 12.4
+    } else if ( strcmp(df_cmd,"precision")==0 ) {
+      if (df==NULL) {
+        mprintf("Error: datafile precision: DataFile %s does not exist.\n",name1);
+        continue;
+      }
+      name2 = A->getNextString();
+      width = A->getNextInteger(12);
+      precision = A->getNextInteger(4);
+      df->SetPrecision(name2,width,precision);
     }
 
   } // END loop over datafile args
@@ -374,7 +389,7 @@
 
   // ========== S E T U P   P H A S E ========== 
   // Calculate frame division among trajectories
-  maxFrames=trajFileList.SetupFrames();
+  maxFrames=trajFileList.SetupFrames(worldrank,worldsize);
 
   // Parameter file information
   parmFileList.Print();
@@ -442,7 +457,7 @@
       // Perform Actions on Frame
       ptrajActionList.DoActions(&CurrentFrame, actionSet);
       // Do Output
-      outFileList.Write(outputSet, CurrentFrame, CurrentParm);
+      outFileList.Write(actionSet, CurrentFrame, CurrentParm);
 #ifdef DEBUG
       dbgprintf("\tDEBUG: %30s: %4i\n",CurrentParm->parmName,CurrentParm->outFrame);
 #endif
diff -urN amber11.orig/AmberTools/src/cpptraj/src/PtrajState.h amber11/AmberTools/src/cpptraj/src/PtrajState.h
--- amber11.orig/AmberTools/src/cpptraj/src/PtrajState.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/PtrajState.h	2011-10-25 15:01:28.093288656 +0300
@@ -20,6 +20,7 @@
     DataFileList DFL;                // List of datafiles that data sets will be written to
     ArgList *A;                      // Current argument list
     std::list<ArgList*> DF_Args;     // List of commands pertaining to datafile creation etc
+    int TotalErrors;                 // Sum of all returned error statuses
     int debug;
 
     void SetGlobalDebug(int);        // Set debug level for all components
diff -urN amber11.orig/AmberTools/src/cpptraj/src/ReferenceList.cpp amber11/AmberTools/src/cpptraj/src/ReferenceList.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/ReferenceList.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/ReferenceList.cpp	2011-10-25 15:01:28.093288656 +0300
@@ -20,11 +20,15 @@
  */
 int ReferenceList::Add(ArgList *A, ParmFileList *parmFileList, int worldsize) {
   TrajFile *T;
-  int startArg;
+  int startArg,stopArg,offsetArg;
+  bool average = false;
 
   // Set up common arguments from arglist
   if (this->ProcessArgList(A,parmFileList)) return 1;
 
+  // Check if we want to obtain the average structure
+  average = A->hasKey("average");
+
   // Set up basic file to determine type and format
   T = this->SetupTrajectory(trajfilename, fileAccess, UNKNOWN_FORMAT, UNKNOWN_TYPE);
 
@@ -45,10 +49,18 @@
   // Get user-specified start arg
   // NOTE: For compatibility with ptraj start from 1
   startArg=A->getNextInteger(1);
-  T->SetArgs(startArg,startArg,1);
+  stopArg=startArg;
+  offsetArg=1;
+  // Get user-specified stop and offset only if getting avg structure
+  if (average) {
+    stopArg=A->getNextInteger(-1);
+    offsetArg=A->getNextInteger(1);
+  }
+  T->SetArgs(startArg,stopArg,offsetArg);
 
   // Add to trajectory file list
-  this->push_back(T); 
+  this->push_back(T);
+  Average.push_back(average); 
 
   return 0;
 }
@@ -60,9 +72,11 @@
  * place that frame in refFrames.
  */
 int ReferenceList::SetupRefFrames(FrameList *refFrames) {
-  int trajFrames;
-  Frame *F;
+  int trajFrames, global_set;
+  double Nframes;
+  Frame *F, *AvgFrame;
   int skipValue;
+  int refTrajNum = 0;
 
   mprintf("\nREFERENCE COORDS:\n");
   if (this->empty()) {
@@ -72,7 +86,13 @@
 
   for (it = this->begin(); it != this->end(); it++) {
     // Setup the reference traj for reading. Should only be 1 frame.
-    trajFrames=(*it)->setupFrameInfo(-1);
+    // NOTE: For MPI, calling setupFrameInfo with worldrank 0, worldsize 1 for 
+    //       all ranks. This is to ensure each thread has a copy of the ref 
+    //       struct.
+    //       Calling setupFrameInfo with -1 to ensure the Parm frame count is
+    //       not updated.
+
+    trajFrames=(*it)->setupFrameInfo(-1,0,1);
     if ((*it)->total_read_frames<1) {
       rprintf("Error: No frames could be read for reference %s, skipping\n",
       (*it)->trajfilename);
@@ -89,12 +109,34 @@
       skipValue=(*it)->skip;
       (*it)->skip=0;
     }
-    (*it)->Begin(&trajFrames, 0);
-    // Get and copy the 1 frame from Traj, then close
-    // NOTE: What happens when not seekable?
+    // Start trajectory read
+    global_set=0;
+    (*it)->Begin(&global_set, 0);
     (*it)->PrintInfo(1);
-    (*it)->NextFrame(&trajFrames);
-    F=(*it)->F->Copy();
+    // If averaging requested, loop over specified frames and avg coords.
+    if (Average[refTrajNum++]) {
+      mprintf("    Averaging over %i frames.\n",trajFrames);
+      AvgFrame = new Frame((*it)->P->natom, (*it)->P->mass);
+      AvgFrame->ZeroCoords();
+      global_set = 0;
+      Nframes = 0.0;
+      while ( (*it)->NextFrame(&global_set) ) {
+        AvgFrame->AddCoord( (*it)->F );
+        Nframes++;
+      }
+      if (Nframes < 1.0) { 
+        mprintf("Error: reference average: # frames read is less than 1.\n");
+        F=NULL;
+      } else {
+        AvgFrame->Divide( Nframes );
+        F=AvgFrame->Copy();
+      }
+      delete AvgFrame; 
+    // If no averaging, get and copy the 1 frame from Traj, then close
+    } else {
+      (*it)->NextFrame(&trajFrames);
+      F=(*it)->F->Copy();
+    }
     // DEBUG
     //fprintf(stdout,"DEBUG: Ref Coord Atom 0\n");
     //F->printAtomCoord(0);
diff -urN amber11.orig/AmberTools/src/cpptraj/src/ReferenceList.h amber11/AmberTools/src/cpptraj/src/ReferenceList.h
--- amber11.orig/AmberTools/src/cpptraj/src/ReferenceList.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/ReferenceList.h	2011-10-25 15:01:28.094288655 +0300
@@ -5,7 +5,7 @@
 #include "FrameList.h"
 
 class ReferenceList : public CoordFileList {
-
+    std::vector<bool> Average;
   public:
     
     ReferenceList();
diff -urN amber11.orig/AmberTools/src/cpptraj/src/RemdTraj.cpp amber11/AmberTools/src/cpptraj/src/RemdTraj.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/RemdTraj.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/RemdTraj.cpp	2011-10-25 15:01:28.122288629 +0300
@@ -88,7 +88,7 @@
   // NOTE: Should check that this is the case for ALL frames.
   stop = T->Frames;
   Frames = T->Frames;
-  isBox = T->isBox;
+  BoxType = T->BoxType;
   trajfilename = T->File->basefilename;
   // Add it to the list
   REMDtraj.push_back(T);
@@ -190,12 +190,12 @@
       return 1;
     }
     // Check that #Frames and box info matches
-    if ( Frames!=T->Frames || isBox!=T->isBox ) {
+    if ( Frames!=T->Frames || BoxType!=T->BoxType ) {
       mprintf(
-              "    ERROR: REMDTRAJ: #Frames (%i) or box info (%i) in replica does not match\n",
-              T->Frames, T->isBox);
-      mprintf("                     values in lowest replica (Frames=%i, box=%i)\n",
-              Frames,isBox);
+              "    ERROR: REMDTRAJ: #Frames (%i) or box type (%i) in replica does not match\n",
+              T->Frames, T->BoxType);
+      mprintf("                     values in lowest replica (Frames=%i, boxtype=%i)\n",
+              Frames,BoxType);
       delete T;
       free(repFilename);
       free(Prefix);
diff -urN amber11.orig/AmberTools/src/cpptraj/src/stringDataSet.cpp amber11/AmberTools/src/cpptraj/src/stringDataSet.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/stringDataSet.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/stringDataSet.cpp	2011-10-25 15:01:28.097288652 +0300
@@ -6,6 +6,13 @@
 #include "PtrajMpi.h"
 #include "CpptrajStdio.h"
 using namespace std;
+
+// CONSTRUCTOR
+stringDataSet::stringDataSet() {
+  dType=STRING;
+  setFormatString();
+}
+
 /*
  * stringDataSet::Xmax(()
  * Return the maximum X value added to this set. By convention this is 
@@ -54,10 +61,10 @@
 
   it = Data.find( frame );
   if (it == Data.end()) { 
-    sprintf(buffer," %s", "NoData");
+    sprintf(buffer, format, "NoData");
     return (buffer + 7);
   } else 
-    sprintf(buffer," %s",(*it).second.c_str());
+    sprintf(buffer, format, (*it).second.c_str());
 
   return (buffer + (*it).second.size() + 1);
 }
diff -urN amber11.orig/AmberTools/src/cpptraj/src/stringDataSet.h amber11/AmberTools/src/cpptraj/src/stringDataSet.h
--- amber11.orig/AmberTools/src/cpptraj/src/stringDataSet.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/stringDataSet.h	2011-10-25 15:01:28.097288652 +0300
@@ -12,6 +12,8 @@
     std::map<int,std::string> Data;
     std::map<int,std::string>::iterator it;
   public:
+    stringDataSet();
+
     int Xmax();
     int isEmpty(int);
     void Add( int, void * );
diff -urN amber11.orig/AmberTools/src/cpptraj/src/TrajFile.cpp amber11/AmberTools/src/cpptraj/src/TrajFile.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/TrajFile.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/TrajFile.cpp	2011-10-25 15:01:28.122288629 +0300
@@ -2,7 +2,6 @@
 #include <cstdlib>
 #include <cstring>
 #include "TrajFile.h"
-#include "PtrajMpi.h" // worldrank and worldsize needed to calc frame division
 #include "CpptrajStdio.h"
 
 // CONSTRUCTOR
@@ -18,7 +17,7 @@
   start=0;
   stop=-1;
   offset=1;
-  isBox=0;
+  BoxType=0;
   title=NULL;
   P=NULL;
   frameskip=0;
@@ -45,12 +44,17 @@
 void TrajFile::SetTitle(char *titleIn) {
   size_t titleSize;
 
+  //mprintf("DEBUG: Attempting to set title for %s: [%s]\n",trajfilename,titleIn);
   if (titleIn==NULL) return;
   titleSize = strlen(titleIn);
-  if (titleSize==0) return;
+  //mprintf("       Title size is %i\n",titleSize);
+  if (titleSize==0) {
+    mprintf("Warning: TrajFile::SetTitle(): Title for %s is 0 length.\n",trajfilename);
+    return;
+  }
   this->title = (char*) malloc( (titleSize+1) * sizeof(char));
   if (this->title==NULL) {
-    mprintf("Error: TrajFile::SetTitle(): Could not allocate memory for title.\n");
+    mprintf("Error: SetTitle: Could not allocate memory for title of %s.\n",trajfilename);
     return;
   }
   strcpy(this->title, titleIn);
@@ -59,6 +63,30 @@
 }
 
 /*
+ * TrajFile::CheckBoxType()
+ * Set the trajectory box type (ortho/nonortho) based on box angles.
+ * Check the current box type against the associated parmfile box type.
+ * Print a warning if they are different.
+ */
+void TrajFile::CheckBoxType(double *box) {
+  // Determine orthogonal / non-orthogonal from angles
+  if (box[3]==0.0 || box[4]==0.0 || box[5]==0.0)
+    BoxType=0;
+  else if (box[3]==90.0 && box[4]==90.0 && box[5]==90.0)
+    BoxType=1;
+  else
+    BoxType=2;
+  if (P->BoxType != BoxType) {
+    mprintf("Warning: %s contains box info of type %i (beta %lf)\n",trajfilename,
+            BoxType,box[4]);
+    mprintf("         but associated parmfile %s has box type %i (beta %lf)\n",P->parmName, 
+            P->BoxType,P->Box[4]);
+    //mprintf("         Box information from trajectory will be used.\n");
+  }
+  if (debug>0) mprintf("    %s: Box type is %i (beta=%lf)\n",trajfilename,BoxType,box[4]);
+}
+
+/*
  * TrajFile::PrintInfo()
  * Print general trajectory information. Call TrajFile->Info for specific information.
  */
@@ -68,7 +96,7 @@
 
   mprintf(", Parm %i",P->pindex);
 
-  if (isBox) mprintf(" (with box info)");
+  if (BoxType>0) mprintf(" (with box info)");
 
   if (showExtended==0) {
     mprintf("\n");
@@ -85,7 +113,7 @@
     mprintf(": Writing %i frames", P->parmFrames);
     if (File->access==APPEND) mprintf(", appended"); // NOTE: Dangerous if REMD
   }
-  if (debug>0) mprintf(", %i atoms, Box %i, seekable %i",P->natom,isBox,seekable);
+  if (debug>0) mprintf(", %i atoms, Box %i, seekable %i",P->natom,BoxType,seekable);
   mprintf("\n");
 }
 
@@ -164,7 +192,7 @@
  * Note that the input frames start counting from 1, output starts counting from 0!
  * If called with maxFrames=-1 dont update the frame in parm file.
  */
-int TrajFile::setupFrameInfo(int maxFrames) {
+int TrajFile::setupFrameInfo(int maxFrames, int worldrank, int worldsize) {
   int Nframes;
   int ptraj_start_frame, ptraj_end_frame;
   int traj_start_frame, traj_end_frame;
diff -urN amber11.orig/AmberTools/src/cpptraj/src/TrajFile.h amber11/AmberTools/src/cpptraj/src/TrajFile.h
--- amber11.orig/AmberTools/src/cpptraj/src/TrajFile.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/TrajFile.h	2011-10-25 15:01:28.128288623 +0300
@@ -25,44 +25,44 @@
     int offset;         // Number of frames to skip while processing
 
     // --== Inherited by child classes ==--
-    virtual int open() { return 0; }        // Open the file, prepare for coord read/write
-    virtual void close() {}                 // Close the file
+    virtual int open() { return 0; } // Open the file, prepare for coord read/write
+    virtual void close() {}          // Close the file
+
+    void CheckBoxType(double *);     // Check that traj boxtype matches parm
 
   public:
     int debug;             // Level of debug information to print
     char *trajfilename;    // The base trajectory filename
-    // NOTE: I hate that the following are public. Only necessary for REMD processing!!
+    // NOTE: I hate that the 2 following are public. Only necessary for REMD processing!!
     int Frames;            // Total number of frames in trajectory
     int total_read_frames; // Total number of frames that will be read
-    int isBox;             // >0 means trajectory has box information
-
+    int BoxType;           // 0: None, 1: Ortho, 2: NonOrtho 
     Range *FrameRange;     // list of frames to be written out
     int hasTemperature;    // 1 means trajectory has temperature information
     PtrajFile *File;       // Class that handles basic file IO
     AmberParm *P;          // Memory address of the associated parmfile
     Frame *F;              // Hold coordinates of the current frame
-    int skip;              /* READ: If =1 do not process this input trajectory 
-                              WRITE: If =1 this traj has been set up for write */
+    int skip;              // READ: If =1 do not process this input trajectory 
+                           // WRITE: If =1 this traj has been set up for write
 
     TrajFile();            // Constructor
     virtual ~TrajFile();   // Destructor - virtual since this class is inherited.
 
-    int Start() { return start; }
+    int Start()        { return start;        }
+    int CurrentFrame() { return currentFrame; }
     void SetTitle(char *);   // Set trajectory title.
     void PrintInfo(int);     // Print trajectory Information
-    int setupFrameInfo(int); // Set actual start/stop based on total #frames and #threads 
-    int Begin(int *, int);   /* Prepare traj for processing. Set output start value, calcd in 
-                              * setupFrameInfo. Allocate memory for F. 
-                              */
-    int Begin();                 // Prepare trajectory for output
-    int NextFrame(int*);         // Put the next target frame into F.
-    void End();                  // Close trajectory and free F memory
-    void progressBar();          // Display trajectory progress to screen
-//    void progressBar2();         // Display trajectory progress to screen
-   
-    void SetArgs(int,int,int);   // Set the stop, start, and offset args from user input
+    int Begin(int *, int);   // Prepare traj for processing. Set output start value, calcd in 
+                             // setupFrameInfo. Allocate memory for F. 
+    int Begin();             // Prepare trajectory for output
+    int NextFrame(int*);     // Put the next target frame into F.
+    void End();              // Close trajectory and free F memory
+    void progressBar();      // Display trajectory progress to screen
+//    void progressBar2();   // Display trajectory progress to screen
+    int setupFrameInfo(int,int,int); // Set actual start/stop based on total #frames and #threads 
+    void SetArgs(int,int,int);       // Set the stop, start, and offset args from user input
     // --== Inherited by child classes ==--
-    virtual int getFrame(int)      { return 1; } // Read the next coord frame into F
+    virtual int getFrame(int)      { return 1; } // Read specified frame into F
     virtual int SetupRead()        { return 1; } // Set file up for reading
     virtual int WriteArgs(ArgList*){ return 0; } // (Opt.) Process any args related to writing
     virtual int SetupWrite()       { return 1; } // Set file up for writing
diff -urN amber11.orig/AmberTools/src/cpptraj/src/TrajinList.cpp amber11/AmberTools/src/cpptraj/src/TrajinList.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/TrajinList.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/TrajinList.cpp	2011-10-25 15:01:28.201288557 +0300
@@ -1,4 +1,5 @@
 // TrajinList
+#include <cstddef>
 #include "TrajinList.h"
 #include "RemdTraj.h"
 #include "CpptrajStdio.h"
@@ -70,7 +71,7 @@
  * actual start and stop and how many frames total will be processed.
  * Return the number of frames to be processed.
  */
-int TrajinList::SetupFrames() {
+int TrajinList::SetupFrames(int worldrank, int worldsize) {
   int maxFrames, trajFrames;
 
   mprintf("\nTRAJECTORIES:\n");
@@ -78,7 +79,7 @@
   maxFrames=0;
 
   for (it = this->begin(); it != this->end(); it++) {
-    trajFrames = (*it)->setupFrameInfo(maxFrames);
+    trajFrames = (*it)->setupFrameInfo(maxFrames,worldrank,worldsize);
     if (trajFrames==-1) {
       maxFrames=-1;
     }
diff -urN amber11.orig/AmberTools/src/cpptraj/src/TrajinList.h amber11/AmberTools/src/cpptraj/src/TrajinList.h
--- amber11.orig/AmberTools/src/cpptraj/src/TrajinList.h	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/TrajinList.h	2011-10-25 15:01:28.090288658 +0300
@@ -13,7 +13,7 @@
     // NOTE: worldsize is passed in as last arg to avoid include of PtrajMpi
     int Add(ArgList *A, ParmFileList *, int);
     // TRAJIN: Set up frames to be processed 
-    int SetupFrames();
+    int SetupFrames(int,int);
 };
 #endif
 
diff -urN amber11.orig/AmberTools/src/cpptraj/src/TrajoutList.cpp amber11/AmberTools/src/cpptraj/src/TrajoutList.cpp
--- amber11.orig/AmberTools/src/cpptraj/src/TrajoutList.cpp	2011-04-14 15:30:16.000000000 +0300
+++ amber11/AmberTools/src/cpptraj/src/TrajoutList.cpp	2011-10-25 15:01:28.202288556 +0300
@@ -1,4 +1,5 @@
 // TrajoutList
+#include <cstddef>
 #include "TrajoutList.h"
 #include "CpptrajStdio.h"
 
@@ -20,7 +21,6 @@
  */
 int TrajoutList::Add(ArgList *A, ParmFileList *parmFileList, int worldsize) {
   TrajFile *T;
-  int boxInfo;
   FileFormat writeFormat;
   FileType writeType;
   char *onlyframes; 
@@ -29,7 +29,6 @@
   if (this->ProcessArgList(A,parmFileList)) return 1;
 
   // Init variables
-  boxInfo=0;
   writeFormat=AMBERTRAJ; 
   writeType=UNKNOWN_TYPE;
  
@@ -56,10 +55,6 @@
   if (worldsize>1 && writeFormat!=AMBERRESTART) 
     writeType=MPIFILE;
 
-  // Set box info from parm file unless nobox is set.
-  boxInfo=P->ifbox;
-  if (A->hasKey("nobox")) boxInfo=0;
-
   // Set up basic file for given type and format
   // If type is unknown it will be determined from extension or will be standard (default)
   T = this->SetupTrajectory(trajfilename, fileAccess, writeFormat, writeType);
@@ -90,10 +85,11 @@
   // Set parameter file
   T->P=P;
 
-  // Set box information (only needed for write)
-  T->isBox=boxInfo;
+  // Set box type from parm file unless "nobox" specified  
+  T->BoxType=P->BoxType;
+  if (A->hasKey("nobox")) T->BoxType=0;
 
-  // No setup here; Write is set up after first frame read in PtrajState::Run
+  // No more setup here; Write is set up when first frame written.
   // Add to trajectory file list
   this->push_back(T); 
 
diff -urN amber11.orig/AmberTools/src/etc/chemistry/amber/readparm.py amber11/AmberTools/src/etc/chemistry/amber/readparm.py
--- amber11.orig/AmberTools/src/etc/chemistry/amber/readparm.py	2011-04-14 15:30:17.000000000 +0300
+++ amber11/AmberTools/src/etc/chemistry/amber/readparm.py	2011-10-25 15:01:28.200288558 +0300
@@ -118,22 +118,44 @@
    """ Parses the fortran format statement. Recognizes ints, exponents, and strings.
        Returns the number of items/line, size of each item, and type of data """
 
+   # Get rid of ( and ) specifiers in Fortran format strings. This is a hack, but
+   # should work for existing chamber prmtop files
+
+   format_string = format_string.replace('(','').replace(')','')
+
+   # Fix case for E, I, and F
+
+   format_string = format_string.replace('e','E')
+   format_string = format_string.replace('i','I')
+   format_string = format_string.replace('f','F')
+
    if 'a' in format_string: # this is a string
       format_parts = format_string.split('a')
-      return int(format_parts[0]), int(format_parts[1]), 'str'
+      try:
+         return int(format_parts[0]), int(format_parts[1]), 'str', None
+      except:
+         return 1, 80, 'str', None
 
    elif 'I' in format_string: # this is an integer
       format_parts = format_string.split('I')
-      return int(format_parts[0]), int(format_parts[1]), 'int'
+      if len(format_parts[0].strip()) == 0: format_parts[0] = 1
+      return int(format_parts[0]), int(format_parts[1]), 'int', None
 
    elif 'E' in format_string: # this is a floating point decimal
       format_parts = format_string.split('E')
       decimal_parts = format_parts[1].split('.')
-      return int(format_parts[0]), int(decimal_parts[0]), 'dec'
+      if len(format_parts[0].strip()) == 0: format_parts[0] = 1
+      return int(format_parts[0]), int(decimal_parts[0]), 'dec', int(decimal_parts[1])
+   
+   elif 'F' in format_string: # this is also a floating point decimal
+      format_parts = format_string.split('F')
+      decimal_parts = format_parts[1].split('.')
+      if len(format_parts[0].strip()) == 0: format_parts[0] = 1
+      return int(format_parts[0]), int(decimal_parts[0]), 'dec', int(decimal_parts[1])
 
    else:
       print >> stderr, 'Error: Unrecognized format "%s"!' % format_string
-      return 1, 80, 'str'
+      return 1, 80, 'str', None
 
 # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
@@ -275,7 +297,7 @@
 
          elif prmlines[i][0:7] == '%FORMAT':
             self.formats[current_flag] = prmlines[i][8:len(prmlines[i].strip())-1]
-            number_items_perline, size_item, dat_type = _parseFormat(self.formats[current_flag])
+            number_items_perline, size_item, dat_type, junk = _parseFormat(self.formats[current_flag])
             gathering_data = True
 
          elif gathering_data:
@@ -339,17 +361,17 @@
          flag = self.flag_list[i]
          new_prm.write('%%FLAG %s\n' % flag)
          new_prm.write('%%FORMAT(%s)\n' % self.formats[flag])
-         number_items_perline, size_item, dat_type = _parseFormat(self.formats[flag])
-         if dat_type == 'dec':
-            decnum = int(self.formats[flag].split('E')[1].split('.')[1])
+         number_items_perline, size_item, dat_type, decnum = _parseFormat(self.formats[flag])
          line = ''
          num_items = 0
          if len(self.parm_data[flag]) == 0: # empty field...
             new_prm.write('\n')
             continue
          for j in range(len(self.parm_data[flag])): # write data in new_prm
-            if dat_type == 'dec':
+            if dat_type == 'dec' and 'E' in self.formats[flag].upper():
                line += ('%%%s.%sE' % (size_item, decnum)) % self.parm_data[flag][j] 
+            elif dat_type == 'dec' and 'F' in self.formats[flag].upper():
+               line += ('%%%s.%sF' % (size_item, decnum)) % self.parm_data[flag][j] 
             elif dat_type == 'int':
                line += ('%%%sd' % size_item) % self.parm_data[flag][j] 
             else:
@@ -764,7 +786,8 @@
          self.LJ_types[self.parm_data["AMBER_ATOM_TYPE"][i]] = self.parm_data["ATOM_TYPE_INDEX"][i]
          
       for i in range(self.pointers["NTYPES"]):
-         lj_index = (i + 1) * (i + 2) / 2 - 1 # n(n+1)/2 th position adjusted for indexing from 0
+         lj_index = self.parm_data["NONBONDED_PARM_INDEX"][
+                     self.pointers["NTYPES"] * i + i - 1] - 1
          if self.parm_data["LENNARD_JONES_BCOEF"][lj_index] < 1.0e-6:
             self.LJ_radius.append(0)
             self.LJ_depth.append(0)
diff -urN amber11.orig/AmberTools/src/leap/src/leap/amber.c amber11/AmberTools/src/leap/src/leap/amber.c
--- amber11.orig/AmberTools/src/leap/src/leap/amber.c	2011-03-10 20:12:06.000000000 +0200
+++ amber11/AmberTools/src/leap/src/leap/amber.c	2011-10-25 15:01:28.139288613 +0300
@@ -36,6 +36,10 @@
  *              UNITs and PARMSETs.
  */
 
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*   	 Added SCEE/SCNB   	*/
+
 #include        "basics.h"
 #include        "vector.h"
 #include        "classes.h"
@@ -240,23 +244,47 @@
  *
  *      Read the proper torsion parameter terms.
  */
+
+/* Arunima Singh added reading in of scee and scnb fields for proper torsions 20110420 */
 static void
 zAmberReadParmSetPropers( PARMSET psParms, FILE *fIn )
 {
 STRING          sLine;
-int             iRead, iN;
+int             iRead, iN, iRead2, iRead3;
 STRING          saStr[10];
-double          dDivisions, dKp, dP0, dN;
+double          dDivisions, dKp, dP0, dN, dScee, dScnb;
+char		*cScee, *cScnb;
 
     memset(saStr, 0, sizeof(saStr));                    /* for Purify */
     while (1) {
         FGETS( sLine, fIn );
         NODASHES(sLine);
-        iRead = sscanf( sLine, "%s %s %s %s %lf %lf %lf %lf", 
+
+	iRead = sscanf( sLine, "%s %s %s %s %lf %lf %lf %lf ", 
                                 saStr[0], saStr[1], saStr[2], saStr[3], 
                                 &dDivisions, &dKp, &dP0, &dN );
-        if ( iRead <= 0 ) 
+
+	cScee = strstr(sLine, "SCEE");
+	if(cScee!=NULL) {
+		iRead2 = sscanf( cScee, "SCEE=%lf", &dScee);
+		iRead++;
+		}
+
+        cScnb = strstr(sLine, "SCNB");	
+        if(cScnb!=NULL) {
+                iRead3 = sscanf( cScnb, "SCNB=%lf", &dScnb);
+                iRead++;
+                }
+
+	if ( iRead <= 0 ) 
                 break;
+
+	if ( iRead == 8 )	/*Arunima Singh*/
+	{
+		dScee = 1.2;
+		dScnb = 2.0;
+	}
+	
         MESSAGE(( "Read: %s\n", sLine ));
 
         if ( sLine[0] == ' ' && sLine[1] == ' ') {
@@ -277,14 +305,37 @@
         zAmberConvertWildCard( saStr[3] );
         iParmSetAddProperTerm( psParms, 
                                 saStr[0], saStr[1], saStr[2], saStr[3],
-                                abs(iN), dKp, dP0*DEGTORAD, "" );
+                                abs(iN), dKp, dP0*DEGTORAD, dScee, dScnb, "" );
+
+
         while( iN < 0 ) {
                 FGETS( sLine, fIn );
                 NODASHES(sLine);
                 MESSAGE(( "Read extra term: %s\n", sLine ));
-                iRead = sscanf( &sLine[11], "%lf %lf %lf %lf",
+                iRead = sscanf( &sLine[11], "%lf %lf %lf %lf ",
                                 &dDivisions, &dKp, &dP0, &dN );
-                if ( iRead<=0 ) break;
+               
+	        cScee = strstr(sLine, "SCEE");
+        	if(cScee!=NULL) {
+                	iRead2 = sscanf( cScee, "SCEE=%lf", &dScee);
+	                iRead++;
+        	        }
+
+	        cScnb = strstr(sLine, "SCNB");
+        	if(cScnb!=NULL) {
+	                iRead3 = sscanf( cScnb, "SCNB=%lf", &dScnb);
+        	        iRead++;
+                	}
+ 
+
+	        if ( iRead == 4 )       /*Arunima Singh*/
+	        {
+	                dScee = 1.2;
+                	dScnb = 2.0;
+        	}
+
+
+		if ( iRead<=0 ) break;
 
                 if ( dDivisions == 0.0 ) 
                         dDivisions = 1.0;
@@ -292,7 +343,7 @@
                 iN = (int)floor(dN+0.5);
                 iParmSetAddProperTerm( psParms,
                                 saStr[0], saStr[1], saStr[2], saStr[3],
-                                abs(iN), dKp, dP0*DEGTORAD, "" );
+                                abs(iN), dKp, dP0*DEGTORAD, dScee, dScnb, "" );
         }
         if ( iRead <= 0 )
                 break;
@@ -311,7 +362,7 @@
 STRING          sLine;
 int             iRead, iN;
 STRING          saStr[10];
-double          dKp, dP0, dN;
+double          dKp, dP0, dN, dScee, dScnb;
 BOOL            bPrintLine;
 
     memset(saStr, 0, sizeof(saStr));                    /* for Purify */
@@ -335,6 +386,8 @@
         zAmberConvertWildCard( saStr[2] );
         zAmberConvertWildCard( saStr[3] );
         iN = (int)dN;
+	dScee = 0.0;
+	dScnb = 0.0;
 
         /*
          *  check everything in case a format or other user error
@@ -362,7 +415,7 @@
 
         iParmSetAddImproperTerm( psParms, 
                                 saStr[0], saStr[1], saStr[2], saStr[3],
-                                iN, dKp, dP0*DEGTORAD, "" );
+                                iN, dKp, dP0*DEGTORAD, dScee, dScnb, "" );
     }
     if ( iRead > 0 )
         VP0(( "WARNING: incomplete Improper Torsion line:\n%s", sLine ));
diff -urN amber11.orig/AmberTools/src/leap/src/leap/build.c amber11/AmberTools/src/leap/src/leap/build.c
--- amber11.orig/AmberTools/src/leap/src/leap/build.c	2011-03-10 20:12:06.000000000 +0200
+++ amber11/AmberTools/src/leap/src/leap/build.c	2011-10-25 15:01:28.140288613 +0300
@@ -42,8 +42,9 @@
  *		
  */
 
-
-
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*      Added SCEE/SCNB   	*/
 
 #include	"basics.h"
 
@@ -1567,7 +1568,7 @@
 LOOP            lAtoms, lTemp;
 ATOM            aAtom, aAtom1, aAtom2, aAtom3, aAtom4;
 BOOL            bM1, bM2, bM3, bM4, bOneMinimizedAtom;
-double          dKb, dR0, dKt, dT0, dTkub, dRkub, dKp, dP0;
+double          dKb, dR0, dKt, dT0, dTkub, dRkub, dKp, dP0, dScee, dScnb;
 STRING		sAtom1, sAtom2, sAtom3, sAtom4, sDesc;
 PARMSET		psTemp;
 TORSION		tTorsion;
@@ -1757,7 +1758,7 @@
 	    ParmSetTORSIONTerm( tTorsion, i,
 	    		&iIndex,
 			sAtom1, sAtom2, sAtom3, sAtom4,
-			&iN, &dKp, &dP0, sDesc );
+			&iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
 	    if ( !bMinimizerAddTorsion( mStrain, 
 	    				aAtom1, aAtom2, aAtom3, aAtom4,
 					(double)iN, dKp, dP0 )) {
diff -urN amber11.orig/AmberTools/src/leap/src/leap/model.c amber11/AmberTools/src/leap/src/leap/model.c
--- amber11.orig/AmberTools/src/leap/src/leap/model.c	2011-04-14 15:30:17.000000000 +0300
+++ amber11/AmberTools/src/leap/src/leap/model.c	2011-10-25 15:01:28.141288612 +0300
@@ -39,7 +39,9 @@
  *              are determined from atom types.
  */
 
-
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*      Added SCEE/SCNB         */
 
 
 #include	"basics.h"
@@ -781,16 +783,6 @@
 	    maPAtom++;
 	}
     }
-    if ( iAtomCoordination(aX) != 
-          1 + maPAtom - &(mtTorsions.maaXBonds[0]) ) {
-	VP0(( "Error: Atom %s has force field coordination %i\n"
-	      "       but only %i bonded neighbors.\n"
-	      "       The cause may be an incorrect atom type, and\n"
-	      "       the effect may be a crash very soon.\n",
-	      sContainerFullDescriptor((CONTAINER)aX,s1),
-	      iAtomCoordination(aX),
-	      1 + maPAtom - &(mtTorsions.maaXBonds[0]) ));
-    }
     for ( i=iAtomCoordination(aX); i<MAXBONDS; i++ ) {
 	maPAtom->aAtom = NULL;
 	maPAtom++;
@@ -824,16 +816,6 @@
 	    maPAtom++;
 	}
     }
-    if ( iAtomCoordination(aY) != 
-          1 + maPAtom - &(mtTorsions.maaYBonds[0]) ) {
-	VP0(( "Error: Atom %s has force field coordination %i\n"
-	      "       but only %i bonded neighbors.\n"
-	      "       The cause may be an incorrect atom type, and\n"
-	      "       the effect may be a crash very soon.\n",
-	      sContainerFullDescriptor((CONTAINER)aY,s1),
-	      iAtomCoordination(aY),
-	      1 + maPAtom - &(mtTorsions.maaYBonds[0]) ));
-    }
     for ( i=iAtomCoordination(aY); i<MAXBONDS; i++ ) {
 	maPAtom->aAtom = NULL;
 	maPAtom++;
@@ -1205,6 +1187,8 @@
 		int	iN;
 		double	dK;
 		double	dE;
+		double  dSce;	/*Arunima Singh*/
+		double  dScn;	/*Arunima Singh*/
 		} H_PROPERPARMt;
 
 typedef	struct	{
@@ -1222,12 +1206,13 @@
 
 	/* Keep iHybrid2 <= iHybrid3 */
 
+/* Arunima Singh 20110413. Added Scee and Scnb AMBER defaults of 1.2 and 2.0 */
 #define	TFORCE	20.0
 static	H_PROPERPARMt	SppaPropers[] = {
-{ 	HSP3,	HSP3,	3,	1.0,		0.0 },	/* Non bond */
-{ 	HSP2,	HSP3,	6,	-2.0,		0.0 },	/* Non bond */
-{	HSP2,	HSP2,	2,	-4.0,		0.0 },	/* Pi bond overlap */
-{	HSP1,	HSP1,	1,	0.0,		0.0 }	/* Not interesting */
+{ 	HSP3,	HSP3,	3,	1.0,		0.0,	1.2,	2.0 },	/* Non bond */
+{ 	HSP2,	HSP3,	6,	-2.0,		0.0,    1.2,    2.0 },	/* Non bond */
+{	HSP2,	HSP2,	2,	-4.0,		0.0,    1.2,    2.0 },	/* Pi bond overlap */
+{	HSP1,	HSP1,	1,	0.0,		0.0,    1.2,    2.0 }	/* Not interesting */
 };
 
 #define	AFORCE	100.0
@@ -1290,6 +1275,8 @@
 					SppaPropers[i].iN,
 					SppaPropers[i].dK,
 					SppaPropers[i].dE,
+					SppaPropers[i].dSce,
+					SppaPropers[i].dScn,
 					sDesc );
 	}
     }
diff -urN amber11.orig/AmberTools/src/leap/src/leap/parmSet.c amber11/AmberTools/src/leap/src/leap/parmSet.c
--- amber11.orig/AmberTools/src/leap/src/leap/parmSet.c	2011-03-10 20:12:06.000000000 +0200
+++ amber11/AmberTools/src/leap/src/leap/parmSet.c	2011-10-25 15:01:28.143288610 +0300
@@ -54,7 +54,9 @@
  *		search routines REQUIRE pre-ordering.
  */
 
-
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*      Added SCEE/SCNB         */
 
 #include	"basics.h"
 
@@ -965,6 +967,8 @@
 	/*
 	 *  copy into 1 vararray & set iType
 	 */
+	
+	/*Arunima Singh added scee and scnb into the database */
 	vaTorsTypes = vaVarArrayCopy2( psLib->vaTorsions, psLib->vaImpropers );
 	tP = PVAI(vaTorsTypes,TORSIONPARMt,0);
 	for (i=0; i<iVarArrayElementCount(psLib->vaTorsions); i++, tP++)
@@ -980,8 +984,12 @@
                 7, "n",
 		    (char *)&(PVAI(vaTorsTypes,TORSIONPARMt,0)->iN),
 		    iVarArrayElementSize(vaTorsTypes),
-                0, NULL, NULL, 0,
-                0, NULL, NULL, 0,
+                9, "scee", 
+		    (char *)&(PVAI(vaTorsTypes,TORSIONPARMt,0)->dScee), 
+		    iVarArrayElementSize(vaTorsTypes),
+                10, "scnb", 
+		    (char *)&(PVAI(vaTorsTypes,TORSIONPARMt,0)->dScnb), 
+		    iVarArrayElementSize(vaTorsTypes),
                 0, NULL, NULL, 0,
                 0, NULL, NULL, 0,
                 0, NULL, NULL, 0,
@@ -1008,7 +1016,7 @@
                 4, "type4",
 		    (char *)&(PVAI(vaTorsTypes,TORSIONPARMt,0)->sType4),
                     iVarArrayElementSize(vaTorsTypes),
-                9, "desc",
+                11, "desc",
 		    (char *)&(PVAI(vaTorsTypes,TORSIONPARMt,0)->sDesc),
                     iVarArrayElementSize(vaTorsTypes)
                 );
@@ -1586,10 +1594,15 @@
  *      Add a torsion parameter to the PARMSET.
  *      Return the index. 
  */
+
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*      Added SCEE/SCNB         */
+
 int
 iParmSetAddProperTerm( PARMSET psLib, 
 	char *sType1, char *sType2, char *sType3, char *sType4, 
-	int iN, double dKp, double dP0, char *sDesc )
+	int iN, double dKp, double dP0, double dScee, double dScnb, char *sDesc )
 {
 TORSIONPARMt    tpTorsion;
 
@@ -1605,6 +1618,8 @@
     tpTorsion.dKp = dKp;
     tpTorsion.iN  = iN;
     tpTorsion.dP0 = dP0;
+    tpTorsion.dScee = dScee;
+    tpTorsion.dScnb = dScnb;
     strcpy( tpTorsion.sOrder, "0123" );
     if ( sDesc != NULL )
     	strcpy( tpTorsion.sDesc, sDesc );
@@ -1633,7 +1648,7 @@
 int
 iParmSetAddImproperTerm( PARMSET psLib, 
 	char *sType1, char *sType2, char *sType3, char *sType4, 
-	int iN, double dKp, double dP0, char *sDesc )
+	int iN, double dKp, double dP0, double dScee, double dScnb, char *sDesc )
 {
 TORSIONPARMt    tpImproper;
 orderStr	sOrder;
@@ -2022,7 +2037,7 @@
 void
 ParmSetTORSIONTerm( TORSION tTorsion, int iTorsionIndex, int *iPParmSetIndex,
 		   char *cPType1, char *cPType2, char *cPType3, char *cPType4,
-		   int *iPN, double *dPKp, double *dPP0, char *sDesc )
+		   int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb, char *sDesc )
 {
 TORSION_MATCHt	*tmPCur;
 
@@ -2035,6 +2050,8 @@
     *iPN = tmPCur->tpTorsion.iN;
     *dPKp = tmPCur->tpTorsion.dKp;
     *dPP0 = tmPCur->tpTorsion.dP0;
+    *dPScee = tmPCur->tpTorsion.dScee;
+    *dPScnb = tmPCur->tpTorsion.dScnb;
     strcpy(sDesc, tmPCur->tpTorsion.sDesc);
 }
 
@@ -2050,7 +2067,7 @@
 BOOL
 bParmSetTORSIONAddProperTerm( TORSION tTorsion,
 	char *cPType1, char *cPType2, char *cPType3, char *cPType4,
-	int iN, double dKp, double dP0, char *sDesc )
+	int iN, double dKp, double dP0, double dScee, double dScnb, char *sDesc )
 {
 TORSIONPARMt	tpTorsion;
 
@@ -2066,6 +2083,8 @@
     tpTorsion.iN = iN;
     tpTorsion.dKp = dKp;
     tpTorsion.dP0 = dP0;
+    tpTorsion.dScee = dScee;
+    tpTorsion.dScnb = dScnb;
     strcpy(tpTorsion.sDesc, sDesc);
     strcpy( tpTorsion.sOrder, "0123" );
     
@@ -2087,7 +2106,7 @@
 BOOL
 bParmSetTORSIONAddImproperTerm( TORSION tTorsion,
 	char *cPType1, char *cPType2, char *cPType3, char *cPType4,
-	int iN, double dKp, double dP0, char *sDesc )
+	int iN, double dKp, double dP0, double dScee, double dScnb, char *sDesc )
 {
 TORSIONPARMt	tpTorsion;
 orderStr	sOrder;
@@ -2104,6 +2123,8 @@
     tpTorsion.iN = iN;
     tpTorsion.dKp = dKp;
     tpTorsion.dP0 = dP0;
+    tpTorsion.dScee = dScee;
+    tpTorsion.dScnb = dScnb;
     strcpy(tpTorsion.sDesc, sDesc);
     strcpy( tpTorsion.sOrder, sOrder );
     
@@ -2516,7 +2537,7 @@
 void
 ParmSetTorsion( PARMSET psLib, int i, 
 	char *sType1, char *sType2, char *sType3, char *sType4,
-	int *iPN, double *dPKp, double *dPP0, char *sDesc)
+	int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb, char *sDesc)
 {
 TORSIONPARMt   *tpPTorsion;
 
@@ -2531,6 +2552,8 @@
 	strcpy( sType4, WILD_CARD_TYPE );
 	*iPN  = 0;
 	*dPKp = 0;
+	*dPScee = 0;
+        *dPScnb = 0;
 	*dPP0 = 0;
 	strcpy( sDesc, "??" );
 	return;
@@ -2543,7 +2566,10 @@
     *iPN  = tpPTorsion->iN;
     *dPKp = tpPTorsion->dKp;
     *dPP0 = tpPTorsion->dP0;
+    *dPScee = tpPTorsion->dScee;
+    *dPScnb = tpPTorsion->dScnb; 
     strcpy( sDesc, tpPTorsion->sDesc );
+
 }
 
 
@@ -2557,7 +2583,7 @@
 void    
 ParmSetImproper( PARMSET psLib, int i, 
 	char *sType1, char *sType2, char *sType3, char *sType4,
-	int *iPN, double *dPKp, double *dPP0, char *sDesc)
+	int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb, char *sDesc)
 {
 TORSIONPARMt   *tpPImproper;
 
@@ -2573,6 +2599,8 @@
 	*iPN  = 0;
 	*dPKp = 0;
 	*dPP0 = 0;
+	*dPScee = 0;
+	*dPScnb = 0;
 	strcpy( sDesc, "??" );
 	return;
     }
@@ -2584,6 +2612,8 @@
     *iPN  = tpPImproper->iN;
     *dPKp = tpPImproper->dKp;
     *dPP0 = tpPImproper->dP0;
+    *dPScee = tpPImproper->dScee;
+    *dPScnb = tpPImproper->dScnb;
     strcpy( sDesc, tpPImproper->sDesc );
 }
 
@@ -2740,7 +2770,7 @@
 void
 ParmSetUpdateTorsion( PARMSET psLib, int i, 
 	char *sType1, char *sType2, char *sType3, char *sType4,
-	int *iPN, double *dPKp, double *dPP0, char *sDescription)
+	int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb, char *sDescription)
 {
 TORSIONPARMt	*tpPTorsion;
 orderStr	sOrder;
@@ -2754,6 +2784,8 @@
     if (         iPN != (int*)NULL   ) tpPTorsion->iN = *iPN;
     if (        dPKp != (double*)NULL) tpPTorsion->dKp = *dPKp;
     if (        dPP0 != (double*)NULL) tpPTorsion->dP0 = *dPP0;
+    if (      dPScee != (double*)NULL) tpPTorsion->dScee = *dPScee;
+    if (      dPScnb != (double*)NULL) tpPTorsion->dScnb = *dPScnb;
     if (sDescription != (char*)NULL  ) strcpy(tpPTorsion->sDesc, sDescription);
 
     strcpy( sOrder, "0123" );
@@ -2777,7 +2809,7 @@
 void
 ParmSetUpdateImproper( PARMSET psLib, int i, 
 	char *sType1, char *sType2, char *sType3, char *sType4,
-	int *iPN, double *dPKp, double *dPP0, char *sDescription)
+	int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb, char *sDescription)
 {
 TORSIONPARMt   *tpPTorsion;
 orderStr	sOrder;
@@ -2790,6 +2822,8 @@
     if (         iPN != (int*)NULL   ) tpPTorsion->iN = *iPN;
     if (        dPKp != (double*)NULL) tpPTorsion->dKp = *dPKp;
     if (        dPP0 != (double*)NULL) tpPTorsion->dP0 = *dPP0;
+    if (      dPScee != (double*)NULL) tpPTorsion->dScee = *dPScee;
+    if (      dPScnb != (double*)NULL) tpPTorsion->dScnb = *dPScnb;
     if (sDescription != (char*)NULL  ) strcpy(tpPTorsion->sDesc, sDescription);
 
     strcpy( sOrder, "0123" );
@@ -2979,6 +3013,7 @@
 			tpPCur->sType1, tpPCur->sType2, 
 			tpPCur->sType3, tpPCur->sType4,
 			tpPCur->iN, tpPCur->dKp, tpPCur->dP0/DEGTORAD,
+			tpPCur->dScee, tpPCur->dScnb,
 			tpPCur->sOrder, tpPCur->sDesc );
 	}
 }
@@ -2996,6 +3031,7 @@
 			tpPCur->sType1, tpPCur->sType2, 
 			tpPCur->sType3, tpPCur->sType4,
 			tpPCur->iN, tpPCur->dKp, tpPCur->dP0/DEGTORAD, 
+			tpPCur->dScee, tpPCur->dScnb,
 			tpPCur->sDesc );
 	}
 }
diff -urN amber11.orig/AmberTools/src/leap/src/leap/parmSet.h amber11/AmberTools/src/leap/src/leap/parmSet.h
--- amber11.orig/AmberTools/src/leap/src/leap/parmSet.h	2011-03-10 20:12:06.000000000 +0200
+++ amber11/AmberTools/src/leap/src/leap/parmSet.h	2011-10-25 15:01:28.144288609 +0300
@@ -42,6 +42,9 @@
  *
  *
  */
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*      Added SCEE/SCNB         */
  
 #ifndef PARMSET_H
 #define PARMSET_H
@@ -96,6 +99,8 @@
 	int		iN;
 	double          dKp;
 	double          dP0;
+	double		dScee;		/* for propers */ /* Arunima Singh */ 
+	double          dScnb;		/* for propers */ /* Arunima Singh */
 	orderStr	sOrder;		/* for impropers */
 	DESCRIPTION     sDesc;
 } TORSIONPARMt;
@@ -158,10 +163,10 @@
 			double dKt, double dT0, double dTkub, double dRkub, char *sDesc);
 extern int	iParmSetAddProperTerm(PARMSET psLib,
 			char *sType1, char *sType2, char *sType3, char *sType4,
-			int iN, double dKp, double dP0, char *sDesc);
+			int iN, double dKp, double dP0, double dScee, double dScnb, char *sDesc);	/* for proper dihedrals */ /* Arunima Singh */
 extern int	iParmSetAddImproperTerm(PARMSET psLib,
 			char *sType1, char *sType2, char *sType3, char *sType4,
-			int iN, double dKp, double dP0, char *sDesc);
+			int iN, double dKp, double dP0, double dScee, double dScnb, char *sDesc);	/* Arunima Singh : added for proper dihedrals, but has to be included in impropers to maintain common data structure usage */ 
 extern int	iParmSetAddHBond(PARMSET psLib, char *sType1, char *sType2,
 			double dA, double dB, char *sDesc);
 
@@ -216,15 +221,15 @@
 extern void	ParmSetTORSIONTerm(TORSION tTorsion, int iTorsionIndex, 
 			int *iPParmSetIndex,
 			char *cPTyp1, char *cPTyp2, char *cPTyp3, char *cPTyp4,
-			int *iPN, double *dPKp, double *dPP0, char *sDesc );
+			int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb, char *sDesc );
 extern BOOL	bParmSetTORSIONAddProperTerm(TORSION tTorsion,
 			char *cPType1, char *cPType2, 
 			char *cPType3, char *cPType4,
-			int iN, double dKp, double dP0, char *sDesc);
+			int iN, double dKp, double dP0, double dScee, double dScnb, char *sDesc);
 extern BOOL	bParmSetTORSIONAddImproperTerm(TORSION tTorsion,
 			char *cPType1, char *cPType2, 
 			char *cPType3, char *cPType4,
-			int iN, double dKp, double dP0, char *sDesc);
+			int iN, double dKp, double dP0, double dScee, double dScnb, char *sDesc);
 extern void	ParmSetTORSIONOrderAtoms();	
 extern void	ParmSetImproperOrderAtoms( TORSION tTorsion, int iTorsionIndex,
 			char *cPaTypes[4], int iaIndexes[4] );
@@ -268,10 +273,10 @@
 			char *sDesc);
 extern void	ParmSetTorsion(PARMSET psLib, int i,
 			char *sType1, char *sType2, char *sType3, char *sType4,
-			int *iPN, double *dPKp, double *dPP0, char *sDesc);
+			int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb, char *sDesc);
 extern void	ParmSetImproper(PARMSET psLib, int i,
 			char *sType1, char *sType2, char *sType3, char *sType4,
-			int *iPN, double *dPKp, double *dPP0, char *sDesc);
+			int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb, char *sDesc);
 extern void	ParmSetHBond(PARMSET psLib, int i, char *sType1, char *sType2,
 			double *dPA, double *dPB, char *sDesc);
 
@@ -296,11 +301,11 @@
 			double *dPKt, double *dPT0, char *sDescription);
 extern void	ParmSetUpdateTorsion(PARMSET psLib, int i,
 			char *sType1, char *sType2, char *sType3, char *sType4,
-			int *iPN, double *dPKp, double *dPP0, 
+			int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb,
 			char *sDescription);
 extern void	ParmSetUpdateImproper(PARMSET psLib, int i,
 			char *sType1, char *sType2, char *sType3, char *sType4,
-			int *iPN, double *dPKp, double *dPP0, 
+			int *iPN, double *dPKp, double *dPP0, double *dPScee, double *dPScnb,
 			char *sDescription);
 extern void	ParmSetUpdateHBond(PARMSET psLib, int i, 
 			char *sType1, char *sType2,
diff -urN amber11.orig/AmberTools/src/leap/src/leap/unitio.c amber11/AmberTools/src/leap/src/leap/unitio.c
--- amber11.orig/AmberTools/src/leap/src/leap/unitio.c	2011-03-10 20:12:06.000000000 +0200
+++ amber11/AmberTools/src/leap/src/leap/unitio.c	2011-10-25 15:01:28.192288568 +0300
@@ -70,6 +70,10 @@
 *       zbUnitIOIndexBondParameters and zUnitDoAtoms are now "extern functions" 
 */ 
 
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*      Added SCEE/SCNB         */
+
 #include <time.h>
 
 #include        "basics.h"
@@ -1585,7 +1589,9 @@
         tC.dKp = tpA->dKp;
         tC.iN = tpA->iN;
         tC.dP0 = tpA->dP0;
-        VarArrayAdd(vaB, (GENP) & tC);
+        tC.dScee = tpA->dScee;
+	tC.dScnb = tpA->dScnb;
+	VarArrayAdd(vaB, (GENP) & tC);
         iIndex++;
         iOldIndex = iParmOffset + iA + 1;
 
@@ -1615,6 +1621,10 @@
                 continue;
             if (tpB->dP0 != tpA->dP0)
                 continue;
+	    if (tpB->dScee != tpA->dScee)
+                continue;
+            if (tpB->dScnb != tpA->dScnb)
+                continue;
 
             /*
              *  B is a duplicate of A
@@ -1698,12 +1708,12 @@
     int iTerm, iPertTerm;
     BOOL bDone, bUse, bUsePert, bCopy, bCopyPert, bEnd, bPertEnd;
     int iN, iPertIndex, iPertN, iLastN, iLastPertN;
-    double dKp, dP0, dPertKp, dPertP0;
+    double dKp, dP0, dScee, dScnb, dPertKp, dPertP0, dPertScee, dPertScnb;
     BOOL bCalc14, bCalcPert14;
 #ifdef  DEBUG2
     STRING s1, s2, s3, s4;
     int iTParm, iTmp;
-    double dTK, dTP;
+    double dTK, dTP, dTScee, dTScnb;
     STRING sT1, sT2, sT3, sT4, sTemp;
 #endif
         STRING sDesc;
@@ -2016,9 +2026,9 @@
             ParmSetTORSIONTerm(tTorsion, i,
                                &iTParm,
                                sT1, sT2, sT3, sT4,
-                               &iTmp, &dTK, &dTP, sTemp);
-            MESSAGE(("Term %3d  %d %s-%s-%s-%s  %d  %lf  %lf\n",
-                     i, iTParm, sT1, sT2, sT3, sT4, iTmp, dTK, dTP));
+                               &iTmp, &dTK, &dTP, &dTScee, &dTScnb, sTemp);
+            MESSAGE(("Term %3d  %d %s-%s-%s-%s  %d  %lf  %lf %lf %lf\n",
+                     i, iTParm, sT1, sT2, sT3, sT4, iTmp, dTK, dTP, dTScee, dTScnb));
         }
         if (bPerturbTorsion) {
             MESSAGE(("Pert%s %s-%s-%s-%s found %d terms\n",
@@ -2029,9 +2039,9 @@
                 ParmSetTORSIONTerm(tPertTorsion, i,
                                    &iTParm,
                                    sT1, sT2, sT3, sT4,
-                                   &iTmp, &dTK, &dTP, sTemp);
-                MESSAGE(("Term %3d  %d %s-%s-%s-%s  %d  %lf  %lf\n",
-                         i, iTParm, sT1, sT2, sT3, sT4, iTmp, dTK, dTP));
+                                   &iTmp, &dTK, &dTP, &dTScee, &dTScnb, sTemp);
+                MESSAGE(("Term %3d  %d %s-%s-%s-%s  %d  %lf  %lf %lf %lf\n",
+                         i, iTParm, sT1, sT2, sT3, sT4, iTmp, dTK, dTP dTScee, dTScnb));
             }
         }
 #endif
@@ -2061,7 +2071,7 @@
             ParmSetTORSIONTerm(tTorsion, iTerm,
                                &iIndex,
                                sAtom1, sAtom2, sAtom3, sAtom4,
-                               &iN, &dKp, &dP0, sDesc);
+                               &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
             MESSAGE(("First non-perturbed multiplicity: %d\n", iN));
         } else {
             if (bProper) {
@@ -2082,7 +2092,7 @@
                 ParmSetTORSIONTerm(tPertTorsion, iPertTerm,
                                    &iPertIndex,
                                    sPert1, sPert2, sPert3, sPert4,
-                                   &iPertN, &dPertKp, &dPertP0, sDesc);
+                                   &iPertN, &dPertKp, &dPertP0, &dPertScee, &dPertScnb, sDesc);
                 MESSAGE(("First perturbed multiplicity: %d\n", iPertN));
             } else
                 bPertEnd = TRUE;
@@ -2175,14 +2185,14 @@
                 if (bProper)
                     iIndex = iParmSetAddProperTerm(uUnit->psParameters,
                                                    sAtom1, sAtom2, sAtom3,
-                                                   sAtom4, iN, dKp, dP0,
-                                                   sDesc);
+                                                   sAtom4, iN, dKp, dP0, 
+                                                   dScee, dScnb, sDesc);
 /*                else if ( !GDefaults.iCharmm )    ???---should I do this????     */
                 else
                     iIndex = iParmSetAddImproperTerm(uUnit->psParameters,
                                                      sAtom1, sAtom2,
                                                      sAtom3, sAtom4, iN,
-                                                     dKp, dP0, sDesc);
+                                                     dKp, dP0, dScee, dScnb, sDesc);
             }
             if (bCopyPert) {
                 if (bProper) {
@@ -2190,13 +2200,13 @@
                                                        sPert1, sPert2,
                                                        sPert3, sPert4,
                                                        iPertN, dPertKp,
-                                                       dPertP0, sDesc);
+                                                       dPertP0, dScee, dScnb, sDesc);
                 } else {
                     iPertIndex =
                         iParmSetAddImproperTerm(uUnit->psParameters,
                                                 sPert1, sPert2, sPert3,
                                                 sPert4, iPertN, dPertKp,
-                                                dPertP0, sDesc);
+                                                dPertP0, dScee, dScnb, sDesc);
                 }
                 MESSAGE(("iPertIndex = %d\n", iPertIndex));
             }
@@ -2215,7 +2225,7 @@
                     ParmSetTORSIONTerm(tTorsion, iTerm,
                                        &iIndex,
                                        sAtom1, sAtom2, sAtom3, sAtom4,
-                                       &iN, &dKp, &dP0, sDesc);
+                                       &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
                 }
                 MESSAGE(
                         ("Advancing non-perturbed multiplicity to %d\n",
@@ -2231,7 +2241,7 @@
                     ParmSetTORSIONTerm(tPertTorsion, iPertTerm,
                                        &iPertIndex,
                                        sPert1, sPert2, sPert3, sPert4,
-                                       &iPertN, &dPertKp, &dPertP0, sDesc);
+                                       &iPertN, &dPertKp, &dPertP0, &dPertScee, &dPertScnb, sDesc);
                 }
                 MESSAGE(
                         ("Advancing perturbed multiplicity to %d\n",
@@ -3988,7 +3998,7 @@
     SAVEATOMt *saPAtom;
     SAVETORSIONt *stPTorsion;
     SAVERESTRAINTt *srPRestraint;
-    double dMass, dPolar, dR, dKb, dR0, dKt, dT0, dTkub, dRkub, dKp, dP0,
+    double dMass, dPolar, dR, dKb, dR0, dKt, dT0, dTkub, dRkub, dKp, dP0, dScee, dScnb,
         dC, dD, dTemp;
     STRING sAtom1, sAtom2, sAtom3, sAtom4, sType1, sType2;
     int iN, iAtoms, iMaxAtoms, iTemp, iAtom, iCalc14, iProper;
@@ -4585,16 +4595,16 @@
              iParmSetTotalImproperParms(uUnit->psParameters)));
     for (i = 0; i < iParmSetTotalTorsionParms(uUnit->psParameters); i++) {
         ParmSetTorsion(uUnit->psParameters, i, sAtom1, sAtom2,
-                       sAtom3, sAtom4, &iN, &dKp, &dP0, sDesc);
-        MESSAGE(("Torsion %d  %s-%s-%s-%s %d %lf %lf\n",
-                 i, sAtom1, sAtom2, sAtom3, sAtom4, iN, dKp, dP0));
+                       sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
+        MESSAGE(("Torsion %d  %s-%s-%s-%s %d %lf %lf %lf %lf\n",
+                 i, sAtom1, sAtom2, sAtom3, sAtom4, iN, dKp, dP0, dScee, dScnb));
         FortranWriteDouble(dKp);
     }
     for (i = 0; i < iParmSetTotalImproperParms(uUnit->psParameters); i++) {
         ParmSetImproper(uUnit->psParameters, i, sAtom1, sAtom2,
-                        sAtom3, sAtom4, &iN, &dKp, &dP0, sDesc);
-        MESSAGE(("Improper %d  %s-%s-%s-%s %d %lf %lf\n",
-                 i, sAtom1, sAtom2, sAtom3, sAtom4, iN, dKp, dP0));
+                        sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
+        MESSAGE(("Improper %d  %s-%s-%s-%s %d %lf %lf %lf %lf\n",
+                 i, sAtom1, sAtom2, sAtom3, sAtom4, iN, dKp, dP0, dScee, dScnb));
         FortranWriteDouble(dKp);
     }
     /* Write the torsion RESTRAINT constants AND set the index */
@@ -4612,13 +4622,13 @@
     FortranFormat(5, DBLFORMAT);
     for (i = 0; i < iParmSetTotalTorsionParms(uUnit->psParameters); i++) {
         ParmSetTorsion(uUnit->psParameters, i, sAtom1, sAtom2,
-                       sAtom3, sAtom4, &iN, &dKp, &dP0, sDesc);
+                       sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
         dTemp = iN;
         FortranWriteDouble(dTemp);
     }
     for (i = 0; i < iParmSetTotalImproperParms(uUnit->psParameters); i++) {
         ParmSetImproper(uUnit->psParameters, i, sAtom1, sAtom2,
-                        sAtom3, sAtom4, &iN, &dKp, &dP0, sDesc);
+                        sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
         dTemp = iN;
         FortranWriteDouble(dTemp);
     }
@@ -4637,12 +4647,12 @@
     FortranFormat(5, DBLFORMAT);
     for (i = 0; i < iParmSetTotalTorsionParms(uUnit->psParameters); i++) {
         ParmSetTorsion(uUnit->psParameters, i, sAtom1, sAtom2,
-                       sAtom3, sAtom4, &iN, &dKp, &dP0, sDesc);
+                       sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
         FortranWriteDouble(dP0);
     }
     for (i = 0; i < iParmSetTotalImproperParms(uUnit->psParameters); i++) {
         ParmSetImproper(uUnit->psParameters, i, sAtom1, sAtom2,
-                        sAtom3, sAtom4, &iN, &dKp, &dP0, sDesc);
+                        sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
         FortranWriteDouble(dP0);
     }
     /* Write the torsion RESTRAINT constants AND set the index */
@@ -4650,6 +4660,60 @@
     RESTRAINTLOOP(RESTRAINTTORSION, dN, i + 1);
     FortranEndLine();
 
+	/*	Arunima Singh (UGA)	*/
+	/*	   20110420		*/
+	/*   Added Printing SCEE/SCNB	*/
+
+
+    /* -17.5A- SCEE for torsions */
+    FortranDebug("-17.5A-");
+    
+    MESSAGE(("Writing SCEE scale factor for torsion interaction\n"));
+    FortranFormat(1, "%-80s");
+    FortranWriteString("%FLAG SCEE_SCALE_FACTOR");
+    FortranWriteString("%FORMAT(5E16.8)");
+    FortranFormat(5, DBLFORMAT);
+    for (i = 0; i < iParmSetTotalTorsionParms(uUnit->psParameters); i++) {
+        ParmSetTorsion(uUnit->psParameters, i, sAtom1, sAtom2,
+                       sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
+        FortranWriteDouble(dScee);
+    }
+    for (i = 0; i < iParmSetTotalImproperParms(uUnit->psParameters); i++) {
+        ParmSetImproper(uUnit->psParameters, i, sAtom1, sAtom2,
+                        sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
+        FortranWriteDouble(dScee);
+    }
+    /* Write the torsion RESTRAINT constants AND set the index */
+    /* for where the interaction can find its constants */
+    RESTRAINTLOOP(RESTRAINTTORSION, dX0, i + 1);
+    FortranEndLine();
+
+    /* -17.5B- SCNB for torsions */
+    FortranDebug("-17.5B-");
+
+    MESSAGE(("Writing SCNB scale factor for torsion interaction\n"));
+    FortranFormat(1, "%-80s");
+    FortranWriteString("%FLAG SCNB_SCALE_FACTOR");
+    FortranWriteString("%FORMAT(5E16.8)");
+    FortranFormat(5, DBLFORMAT);
+    for (i = 0; i < iParmSetTotalTorsionParms(uUnit->psParameters); i++) {
+        ParmSetTorsion(uUnit->psParameters, i, sAtom1, sAtom2,
+                       sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
+        FortranWriteDouble(dScnb);
+    }
+    for (i = 0; i < iParmSetTotalImproperParms(uUnit->psParameters); i++) {
+        ParmSetImproper(uUnit->psParameters, i, sAtom1, sAtom2,
+                        sAtom3, sAtom4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc);
+        FortranWriteDouble(dScnb);
+    }
+    /* Write the torsion RESTRAINT constants AND set the index */
+    /* for where the interaction can find its constants */
+    RESTRAINTLOOP(RESTRAINTTORSION, dX0, i + 1);
+    FortranEndLine();
+	
+	/*     	    Arunima Singh	*/
+	/*    End of adding SCEE/SCNB	*/
+
     /* -18- Not used, reserved for future use, uses NATYP */
     /* Corresponds to the AMBER SOLTY array */
     FortranDebug("-18-");
@@ -6009,7 +6073,7 @@
 SAVEATOMt       *saPAtom;
 SAVETORSIONt    *stPTorsion;
 SAVERESTRAINTt  *srPRestraint;
-double          dMass, dPolar, dR, dKb, dR0, dKt, dT0, dTkub, dRkub, dKp, dP0, dC, dD, dTemp;
+double          dMass, dPolar, dR, dKb, dR0, dKt, dT0, dTkub, dRkub, dKp, dP0, dScee, dScnb, dC, dD, dTemp;
 STRING          sAtom1, sAtom2, sAtom3, sAtom4, sType1, sType2;
 int             iN, iAtoms, iMaxAtoms, iTemp, iAtom, iCalc14, iProper;
 int             iElement, iHybridization, iStart, iFirstSolvent;
@@ -6547,19 +6611,19 @@
     for ( i=0; i<iParmSetTotalTorsionParms(uUnit->psParameters); i++ ) {
         ParmSetTorsion( uUnit->psParameters, i, sAtom1, sAtom2, 
                         sAtom3, sAtom4,
-                        &iN, &dKp, &dP0, sDesc );
-        MESSAGE(( "Torsion %d  %s-%s-%s-%s %d %lf %lf\n",
+                        &iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
+        MESSAGE(( "Torsion %d  %s-%s-%s-%s %d %lf %lf %lf %lf\n",
                         i, sAtom1, sAtom2, sAtom3, sAtom4,
-                        iN, dKp, dP0 ));
+                        iN, dKp, dP0, dScee, dScnb ));
         FortranWriteDouble( dKp );
     }
     for ( i=0; i<iParmSetTotalImproperParms(uUnit->psParameters); i++ ) {
         ParmSetImproper( uUnit->psParameters, i, sAtom1, sAtom2, 
                         sAtom3, sAtom4,
-                        &iN, &dKp, &dP0, sDesc );
-        MESSAGE(( "Improper %d  %s-%s-%s-%s %d %lf %lf\n",
+                        &iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
+        MESSAGE(( "Improper %d  %s-%s-%s-%s %d %lf %lf %lf %lf\n",
                         i, sAtom1, sAtom2, sAtom3, sAtom4,
-                        iN, dKp, dP0 ));
+                        iN, dKp, dP0, dScee, dScnb ));
         FortranWriteDouble( dKp );
     }
                 /* Write the torsion RESTRAINT constants AND set the index */
@@ -6575,14 +6639,14 @@
     for ( i=0; i<iParmSetTotalTorsionParms(uUnit->psParameters); i++ ) {
         ParmSetTorsion( uUnit->psParameters, i, sAtom1, sAtom2, 
                         sAtom3, sAtom4,
-                        &iN, &dKp, &dP0, sDesc );
+                        &iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
         dTemp = iN;
         FortranWriteDouble( dTemp );
     }
     for ( i=0; i<iParmSetTotalImproperParms(uUnit->psParameters); i++ ) {
         ParmSetImproper( uUnit->psParameters, i, sAtom1, sAtom2, 
                         sAtom3, sAtom4,
-                        &iN, &dKp, &dP0, sDesc );
+                        &iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
         dTemp = iN;
         FortranWriteDouble( dTemp );
     }
@@ -6599,13 +6663,13 @@
     for ( i=0; i<iParmSetTotalTorsionParms(uUnit->psParameters); i++ ) {
         ParmSetTorsion( uUnit->psParameters, i, sAtom1, sAtom2, 
                         sAtom3, sAtom4,
-                        &iN, &dKp, &dP0, sDesc );
+                        &iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
         FortranWriteDouble( dP0 );
     }
     for ( i=0; i<iParmSetTotalImproperParms(uUnit->psParameters); i++ ) {
         ParmSetImproper( uUnit->psParameters, i, sAtom1, sAtom2, 
                         sAtom3, sAtom4,
-                        &iN, &dKp, &dP0, sDesc );
+                        &iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
         FortranWriteDouble( dP0 );
     }
                 /* Write the torsion RESTRAINT constants AND set the index */
diff -urN amber11.orig/AmberTools/src/leap/src/leap/xaImproperParmTable.c amber11/AmberTools/src/leap/src/leap/xaImproperParmTable.c
--- amber11.orig/AmberTools/src/leap/src/leap/xaImproperParmTable.c	2011-03-10 20:12:06.000000000 +0200
+++ amber11/AmberTools/src/leap/src/leap/xaImproperParmTable.c	2011-10-25 15:01:28.193288566 +0300
@@ -37,7 +37,9 @@
  *		Handle editing of parameters in a table format.
  */
 
-
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*      Added SCEE/SCNB         */
 
 #include	<X11/IntrinsicP.h>
 #include	<X11/StringDefs.h>
@@ -59,7 +61,10 @@
 #define	NC		4
 #define	KPC		5
 #define P0C		6
-#define DESCC		7
+#define SCEE            7       /*Arunima Singh*/
+#define SCNB            8       /*Arunima Singh*/
+#define DESCC           9       /*Arunima Singh: Changed value from 7 to 9 to include scee and scnb*/
+ 
 
 #define	MAXTYPELEN	5
 #define DESCLEN		32
@@ -129,13 +134,15 @@
 int			iN;
 double			dKp;
 double			dP0;
+double			dScee;
+double			dScnb;
 char			sDesc[DESCLEN];
 
 
     iptPCur = (IMPROPERPARMTABLEt*)PXATClientPointer(tTable);
     
     ParmSetImproper( iptPCur->psParmSet, iRow, 
-	    sType1, sType2, sType3, sType4, &iN, &dKp, &dP0, sDesc );
+	    sType1, sType2, sType3, sType4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
 
     switch ( iCol ) {
 	    case TYPE1C:
@@ -171,6 +178,14 @@
 	    	}
 		return(SsBuffer);
 		break;
+            case SCEE:
+                sprintf( SsBuffer, DBLFMT, dScee );
+                return(SsBuffer);
+                break;
+            case SCNB:
+                sprintf( SsBuffer, DBLFMT, dScnb );
+                return(SsBuffer);
+                break;
 	    case DESCC:
 	    	strcpy( SsBuffer, sDesc );
 		return( SsBuffer );
@@ -259,6 +274,16 @@
 		if ( !strcmp( cPData, "0" ))  break;
 		return("P0 field must be '0' or 'Pi'.");
 		break;
+            case SCEE:
+                if ( !bStringToDouble( cPData, &dValue ) ) {
+                    return("Invalid character in Scee field.");
+                }
+                break;
+            case SCNB:
+                if ( !bStringToDouble( cPData, &dValue ) ) {
+                    return("Invalid character in Scnb field.");
+                }
+                break;
 	    case DESCC:
 		if ( strlen(cPData)>DESCLEN-1 ) {
 		    sprintf( SsError, "%s %d characters.",
@@ -384,11 +409,33 @@
 		return("P0 field must be '0' or 'Pi'.");
 	}
 
+        /*
+         *  Scee
+         */
+        *iPErrCol = 7;
+        cPData = col[7];
+        if ( !bStringToDouble( cPData, &dValue ) ) {
+                return("Invalid character in Scee field.");
+        } else if ( dValue < 0.0 ) {
+                return("Scee cannot be negative.");
+        }
+
+        /*
+         *  Scnb
+         */
+        *iPErrCol = 8;
+        cPData = col[8];
+        if ( !bStringToInt( cPData, &iValue ) ) {
+                return("Invalid character in Scnb field.");
+        } else if ( dValue < 0.0 ) {
+                return("Scnb cannot be negative.");
+        }
+
 	/*
 	 *  Desc
 	 */
-	*iPErrCol = 7;
-	cPData = col[7];
+	*iPErrCol = 9;
+	cPData = col[9];
 	if ( strlen(cPData) > DESCLEN-1 ) {
 		sprintf( SsError, "%s %d characters.",
 			"Parameter Description cannot be longer than",
@@ -413,7 +460,8 @@
 int			iN;
 double			dKp;
 double			dP0;
-
+double			dScee;
+double			dScnb;
 
 	iptPCur = (IMPROPERPARMTABLEt*) PXATClientPointer(tTable);
 	psParmSet = iptPCur->psParmSet;
@@ -444,7 +492,7 @@
 					col[0], col[1], col[2], col[3] ));
         	if ( iRow != iParmSetAddImproperTerm( psParmSet,
 					col[0], col[1], col[2], col[3],
-					iN, dKp, dP0, col[7] ) )
+					iN, dKp, dP0, dScee, dScnb, col[9] ) )
 			DFATAL(( "programming err 2 in zXAIPTAcceptRow\n" ));
 	} else {
 		/*
@@ -452,7 +500,7 @@
 		 */
 		ParmSetUpdateImproper( psParmSet, iRow, 
 				col[0], col[1], col[2], col[3],
-				&iN, &dKp, &dP0, col[7] );
+				&iN, &dKp, &dP0, &dScee, &dScnb, col[9] );
 	}
 }
 
diff -urN amber11.orig/AmberTools/src/leap/src/leap/xaTorsionParmTable.c amber11/AmberTools/src/leap/src/leap/xaTorsionParmTable.c
--- amber11.orig/AmberTools/src/leap/src/leap/xaTorsionParmTable.c	2011-03-10 20:12:06.000000000 +0200
+++ amber11/AmberTools/src/leap/src/leap/xaTorsionParmTable.c	2011-10-25 15:01:28.194288563 +0300
@@ -37,6 +37,9 @@
  *		Handle editing of parameters in a table format.
  */
 
+        /*      Arunima Singh (UGA)     */
+        /*         20110420             */
+        /*      Added SCEE/SCNB         */
 
 #include	<X11/IntrinsicP.h>
 #include	<X11/StringDefs.h>
@@ -58,7 +61,9 @@
 #define	NC		4
 #define	KPC		5
 #define P0C		6
-#define DESCC		7
+#define SCEE		7	/*Arunima Singh*/
+#define SCNB		8	/*Arunima Singh*/
+#define DESCC		9	/*Arunima Singh: Changed value from 7 to 9 to include scee and scnb*/
 
 #define	MAXTYPELEN	5
 #define DESCLEN		32
@@ -112,7 +117,7 @@
  *	zcPXATPTGetElement
  *
  *	Get the values for the elements of the TABLE from the
- *	particular Torsion Parmeter Entry.
+ *	particular Torsion Parameter Entry.
  */
 static char *
 zcPXATPTGetElement( TABLE tTable, int iCol, int iRow )
@@ -126,13 +131,15 @@
 int			iN;
 double			dKp;
 double			dP0;
+double			dScee;
+double			dScnb;
 char			sDesc[DESCLEN];
 
 
     tptPCur = (TORSIONPARMTABLEt*)PXATClientPointer(tTable);
     
     ParmSetTorsion( tptPCur->psParmSet, iRow, 
-	    sType1, sType2, sType3, sType4, &iN, &dKp, &dP0, sDesc );
+	    sType1, sType2, sType3, sType4, &iN, &dKp, &dP0, &dScee, &dScnb, sDesc );
     
     switch ( iCol ) {
 	    case TYPE1C:
@@ -168,6 +175,14 @@
 	    	}
 		return(SsBuffer);
 		break;
+	    case SCEE:
+		sprintf( SsBuffer, DBLFMT, dScee );
+		return(SsBuffer);
+                break;
+            case SCNB:
+                sprintf( SsBuffer, DBLFMT, dScnb );
+                return(SsBuffer);
+                break; 
 	    case DESCC:
 	    	strcpy( SsBuffer, sDesc );
 		return( SsBuffer );
@@ -256,6 +271,16 @@
 		if ( !strcmp( cPData, "0" ))  break;
 		return("P0 field must be '0' or 'Pi'.");
 		break;
+            case SCEE:
+                if ( !bStringToDouble( cPData, &dValue ) ) {
+                    return("Invalid character in Scee field.");
+                }
+                break;
+            case SCNB:
+                if ( !bStringToDouble( cPData, &dValue ) ) {
+                    return("Invalid character in Scnb field.");
+                }
+                break;
 	    case DESCC:
 		if ( strlen(cPData)>DESCLEN-1 ) {
 		    sprintf( SsError, "%s %d characters.",
@@ -379,11 +404,33 @@
 		return("P0 field must be '0' or 'Pi'.");
 	}
 
+        /*
+         *  Scee
+         */
+        *iPErrCol = 7;
+        cPData = col[7];
+        if ( !bStringToDouble( cPData, &dValue ) ) {
+                return("Invalid character in Scee field.");
+        } else if ( dValue < 0.0 ) {
+                return("Scee cannot be negative.");
+        }
+
+        /*
+         *  Scnb
+         */
+        *iPErrCol = 8;
+        cPData = col[8];
+        if ( !bStringToInt( cPData, &iValue ) ) {
+                return("Invalid character in Scnb field.");
+        } else if ( dValue < 0.0 ) {
+                return("Scnb cannot be negative.");
+        }
+
 	/*
 	 *  Desc
 	 */
-	*iPErrCol = 7;
-	cPData = col[7];
+	*iPErrCol = 9;
+	cPData = col[9];
 	if ( strlen(cPData) > DESCLEN-1 ) {
 		sprintf( SsError, "%s %d characters.",
 			"Parameter Description cannot be longer than",
@@ -408,6 +455,8 @@
 int			iN;
 double			dKp;
 double			dP0;
+double			dScee;
+double			dScnb;
 
 	tptPCur = (TORSIONPARMTABLEt*) PXATClientPointer(tTable);
 	psParmSet = tptPCur->psParmSet;
@@ -438,15 +487,15 @@
 					col[0], col[1], col[2], col[3] ));
         	if ( iRow != iParmSetAddProperTerm( psParmSet,
 					col[0], col[1], col[2], col[3],
-					iN, dKp, dP0, col[7] ) )
-			DFATAL(( "programming err 2 in zXATPTAcceptRow\n" ));
+					iN, dKp, dP0, dScee, dScnb, col[9] ) )	/*Arunima singh*/
+			DFATAL(( "programming err 2 in zXATPTAcceptRow\n" ));	
 	} else {
 		/*
 		 *  update row in place
 		 */
 		ParmSetUpdateTorsion( psParmSet, iRow, 
 				col[0], col[1], col[2], col[3],
-				&iN, &dKp, &dP0, col[7] );
+				&iN, &dKp, &dP0, &dScee, &dScnb, col[9] );	/*Arunima singh*/
 	}
 }
 
diff -urN amber11.orig/AmberTools/src/mmpbsa_py/MMPBSA_mods/alamdcrd.py amber11/AmberTools/src/mmpbsa_py/MMPBSA_mods/alamdcrd.py
--- amber11.orig/AmberTools/src/mmpbsa_py/MMPBSA_mods/alamdcrd.py	2011-04-14 15:30:17.000000000 +0300
+++ amber11/AmberTools/src/mmpbsa_py/MMPBSA_mods/alamdcrd.py	2011-10-25 15:01:28.132288620 +0300
@@ -371,7 +371,7 @@
          coords_received = _scaledistance(coords_tosend, chdist)
 
          for i in range(3):
-            new_coords.append(coords_received[x+3])
+            new_coords.append(coords_received[i+3])
 
          coords_tosend = []
          coords_received = []
diff -urN amber11.orig/AmberTools/src/mmpbsa_py/MMPBSA.pypp amber11/AmberTools/src/mmpbsa_py/MMPBSA.pypp
--- amber11.orig/AmberTools/src/mmpbsa_py/MMPBSA.pypp	2011-04-14 15:30:17.000000000 +0300
+++ amber11/AmberTools/src/mmpbsa_py/MMPBSA.pypp	2011-10-25 15:01:28.238288523 +0300
@@ -412,6 +412,7 @@
    INPUT['solvcut']        = float(INPUT['solvcut'])
    INPUT['tolerance']      = float(INPUT['tolerance'])
    INPUT['rism_verbose']   =   int(INPUT['rism_verbose'])
+   INPUT['inp']            =   int(INPUT['inp'])
 except ValueError, err:
    print >> sys.stderr, 'Error: Invalid input data types! Check input file for proper float/int/string arguments.'
    print >> sys.stderr, '       %s' % err
@@ -998,7 +999,7 @@
          if master: MMPBSA_timer.StartTimer('ptraj')
 
          # create the dummy inpcrd files
-         if isinerr != 1 and (INPUT['gbrun'] or INPUT['pbrun']):
+         if isinerr != 1 and (INPUT['gbrun'] or INPUT['pbrun'] or INPUT['rismrun']):
             os.system('%s %s _MMPBSA_mutant_complexinpcrd.in > _MMPBSA_ptraj9.out 2>&1' % (ptraj, FILES['mutant_complex_prmtop']))
             if not stability and FILES['mutant_receptor_prmtop'] == FILES['receptor_prmtop']:
                os.system('%s %s _MMPBSA_mutant_ligandinpcrd.in > _MMPBSA_ptraj11.out 2>&1' % (ptraj, FILES['mutant_ligand_prmtop']))
diff -urN amber11.orig/AmberTools/src/mmpbsa_py/setup.sh amber11/AmberTools/src/mmpbsa_py/setup.sh
--- amber11.orig/AmberTools/src/mmpbsa_py/setup.sh	2011-04-14 15:30:18.000000000 +0300
+++ amber11/AmberTools/src/mmpbsa_py/setup.sh	2011-10-25 15:01:28.133288619 +0300
@@ -10,7 +10,8 @@
 
 # require AMBERHOME
 if [ -z $AMBERHOME ]; then
-   export AMBERHOME=`dirname \`dirname $PWD\``
+   AMBERHOME=`dirname \`dirname $PWD\``
+   export AMBERHOME=`dirname $AMBERHOME`
    echo "AMBERHOME is not set.  Assuming it is $AMBERHOME"
 fi
 
diff -urN amber11.orig/AmberTools/src/pbsa/amg1r5.f amber11/AmberTools/src/pbsa/amg1r5.f
--- amber11.orig/AmberTools/src/pbsa/amg1r5.f	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/pbsa/amg1r5.f	2011-10-25 15:01:28.203288555 +0300
@@ -3707,7 +3707,7 @@
 
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 !+ [Enter a one-line description of real function cgeps here]
-real function cgeps(k,s2,a,u,f,ia,ja,iw, &
+_REAL_ function cgeps(k,s2,a,u,f,ia,ja,iw, &
       imin,imax,iminw,m,ierr,ium)
    
    implicit _REAL_ (a-h,o-z)
@@ -3753,7 +3753,7 @@
 
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 !+ [Enter a one-line description of real function cgalf here]
-real function cgalf(k,s2,a,u,f,ia,ja,iw, &
+_REAL_ function cgalf(k,s2,a,u,f,ia,ja,iw, &
       imin,imax,iminw,m)
    
    implicit _REAL_ (a-h,o-z)
@@ -3971,7 +3971,7 @@
 
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 !+ [Enter a one-line description of real function random here]
-real function random(s)
+_REAL_ function random(s)
    
    !     FUNCTION TO CREATE "RANDOM" SEQUENCE OF NUMBERS BETWEEN 0 AND 0.1
    
diff -urN amber11.orig/AmberTools/src/pbsa/Makefile amber11/AmberTools/src/pbsa/Makefile
--- amber11.orig/AmberTools/src/pbsa/Makefile	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/pbsa/Makefile	2011-10-25 15:01:28.228288532 +0300
@@ -204,6 +204,14 @@
 	   cd ../c9x-complex && $(MAKE) libmc.a; \
 	 fi
 
+pb_init.o: pb_init.f
+	$(FPP) $(FPPFLAGS) $(AMBERFPPFLAGS) $< > _$<
+	$(FC) -c -O0 $(FFLAGS) $(AMBERFFLAGS) -o $@ _$<
+
+pb_init.SANDER.o: pb_init.f
+	$(FPP) $(FPPFLAGS) $(AMBERFPPFLAGS) -DSANDER $< > _$<
+	$(FC) -c -O0 $(FFLAGS) $(AMBERFFLAGS) -o $@ _$<
+
 %.LIBPBSA.o: %.f
 	$(FPP) $(FPPFLAGS) $(AMBERFPPFLAGS) -DLIBPBSA $< > _$<
 	$(FC) -c $(FOPTFLAGS) $(FFLAGS) $(AMBERFFLAGS) -o $@ _$<
diff -urN amber11.orig/AmberTools/src/ptraj/actions.c amber11/AmberTools/src/ptraj/actions.c
--- amber11.orig/AmberTools/src/ptraj/actions.c	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/ptraj/actions.c	2011-10-25 15:01:28.235288526 +0300
@@ -46,6 +46,7 @@
 #include "ptraj.h"
 #include <string.h>
 #include <stdarg.h>
+#include <float.h>
 
 /*
  *  The code in this file implements the various "actions" of ptraj to
@@ -4809,8 +4810,14 @@
    *  set the minimum distance to the solute to be larger than 
    *  any possible (imaged!!!) distance
    */
-  min = box[0] + box[1] + box[2];
-  min = min * min;
+  if (box[0]!=0.0 && box[1]!=0.0 && box[2]!=0.0) {
+    min = box[0] + box[1] + box[2];
+    min = min * min;
+  } else {
+    // No box information, set to arbitrarily large max
+    min=DBL_MAX;
+  }
+
   for (i=0; i < oldstate->solventMolecules; i++) {
     minDistance[i] = min;
     sortindex[i] = i;
@@ -16752,9 +16759,12 @@
      */
 
     structInfo = (transformSecondaryStructInfo *) action->carg1;
-    if (structInfo->filename != NULL)
+    if (structInfo->filename != NULL) {
+      i = (int) strlen(structInfo->filename);
+      i+=5;
+      structInfo->filename = (char*) realloc(structInfo->filename, i*sizeof(char));
       outFile = safe_fopen(strcat(structInfo->filename, ".sum"), "w");
-    else
+    } else
       outFile = stdout;
 
     fprintf(outFile, "#ResNum\t3-10-Helix\talpha-helix\tPI-Helix\tparallel-Sheet\tantip.-Sheet\tTurn\n");
@@ -18123,17 +18133,26 @@
     /*
      *  process the remaining arguments
      */
-    if ( (buffer = argumentStackKeyToString(argumentStackPointer, "principal", NULL)) != NULL ) {
+    if ( argumentStackContains(argumentStackPointer, "principal")  ) {
       vectorInfo->mode = VECTOR_PRINCIPAL_X;
-      if (strcmp(buffer, "x") == 0) 
-	vectorInfo->mode = VECTOR_PRINCIPAL_X;
-      else if (strcmp(buffer, "y") == 0) 
-	vectorInfo->mode = VECTOR_PRINCIPAL_Y;
-      else if (strcmp(buffer, "z") == 0) 
-	vectorInfo->mode = VECTOR_PRINCIPAL_Z;
-      safe_free(buffer);
-    } 
-    else if (argumentStackContains(argumentStackPointer, "dipole")) 
+      /* DRR - Check the next argument for x, y, or z. If none of these 
+       *       are present, put the argument back on the stack.
+       */
+      buffer = getArgumentString(argumentStackPointer, NULL);
+      if (buffer!=NULL) {
+        if (strcmp(buffer, "x") == 0) { 
+          vectorInfo->mode = VECTOR_PRINCIPAL_X; 
+          safe_free(buffer);
+        } else if (strcmp(buffer, "y") == 0) {
+	  vectorInfo->mode = VECTOR_PRINCIPAL_Y;
+          safe_free(buffer);
+        } else if (strcmp(buffer, "z") == 0) {
+	  vectorInfo->mode = VECTOR_PRINCIPAL_Z;
+          safe_free(buffer);
+        } else
+          pushBottomStack(argumentStackPointer, buffer); 
+      }
+    } else if (argumentStackContains(argumentStackPointer, "dipole")) 
       vectorInfo->mode = VECTOR_DIPOLE;
     else if (argumentStackContains(argumentStackPointer, "box")) 
       vectorInfo->mode = VECTOR_BOX;
@@ -18263,6 +18282,11 @@
        vectorInfo->mode == VECTOR_CORRIRED ||
        vectorInfo->mode == VECTOR_MASK){
       buffer = getArgumentString(argumentStackPointer, NULL);
+      if (buffer==NULL) {
+        fprintf(stdout,"Error: vector: specified vector mode requires a second mask.\n");
+        freeTransformVectorMemory(action);
+        return -1;
+      }
       vectorInfo->mask2 = processAtomMask(buffer, action->state);
       safe_free(buffer);
     }
@@ -18885,7 +18909,7 @@
   /*
    *  USAGE:
    *
-   *    watershell mask [lower <lower cut>] [upper <upper cut>] [noimage]
+   *    watershell mask filename [lower <lower cut>] [upper <upper cut>] [noimage]
    *
    *  action argument usage:
    *
@@ -18917,11 +18941,25 @@
     action->iarg1 = argumentStackContains(argumentStackPointer, "noimage");
 
     buffer = getArgumentString(argumentStackPointer, NULL);
+    if (buffer==NULL) {
+      fprintf(stdout,"ERROR: WATERSHELL: Solute mask must be specified.\n");
+      return -1;
+    }
+
     info->soluteMask = processAtomMask(buffer, action->state);
+    if (info->soluteMask==NULL) {
+      fprintf(stdout,"ERROR: WATERSHELL: Solute mask %s corresponds to 0 atoms.\n",buffer);
+      safe_free(buffer);
+      return -1;
+    }
     safe_free(buffer);
 
     info->filename = getArgumentString(argumentStackPointer, NULL);
-    
+    if (info->filename==NULL) {
+      fprintf(stdout,"ERROR: WATERSHELL: Output filename must be specified.\n");
+      return -1;
+    }
+
     info->lowerCutoff = 
       argumentStackKeyToDouble(argumentStackPointer, "lower", info->lowerCutoff);
     info->upperCutoff = 
@@ -18932,6 +18970,17 @@
       info->solventMask = processAtomMask(buffer, action->state);
     else
       info->solventMask = processAtomMask(":WAT", action->state);
+    if (info->solventMask==NULL) {
+      if (buffer!=NULL)
+        fprintf(stdout,"ERROR: WATERSHELL: Solvent mask %s corresponds to 0 atoms.\n",buffer);
+      else {
+        fprintf(stdout,"ERROR: WATERSHELL: Default solvent mask :WAT corresponds to 0 atoms.\n");
+        fprintf(stdout,
+          "                   Solvent mask can be specified as the third argument.\n");
+      }
+      safe_free(buffer);
+      return -1;
+    }
     safe_free(buffer);
 
     action->carg1 = (void *) info;
diff -urN amber11.orig/AmberTools/src/ptraj/ptraj.c amber11/AmberTools/src/ptraj/ptraj.c
--- amber11.orig/AmberTools/src/ptraj/ptraj.c	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/ptraj/ptraj.c	2011-10-25 15:01:28.224288536 +0300
@@ -2059,7 +2059,8 @@
   int start = 1;
   int stop = 1;
   int frame_lines, title_size, seekable;
-  long long int file_size, frame_size;
+  int maxi, sizeFound; // For large gzip file calc, Amber Traj
+  long long int file_size, frame_size, tmpfsize;
   long int endoffset;
   float *binposScratch;
   FILE *fp;
@@ -2439,16 +2440,54 @@
       file_size = file_size - frame_size; // Subtract title size from file total size.
       frame_size = (long long int) trajInfo->frameSize;
       trajInfo->Nframes = (int) (file_size / frame_size);
+
+      // Frame calculation for large gzip files
+      // If uncompressed size is less than compressed size, uncompressed
+      // size is likely > 4GB.
+      if (trajInfo->compressType == 1 && file_size < (long long int)frame_stat.st_size) {
+        // Since this is gzip compressed, if the file_size % frame size != 0, 
+        // it could be that the uncompressed filesize > 4GB. Since 
+        //   ISIZE = uncompressed % 2^32, 
+        // try ((file_size + (2^32 * i)) % frame_size) and see if any are 0.
+        if ( (file_size % frame_size) != 0) {
+          // Determine the maximum number of iterations to try based on the
+          // fact that Amber trajectories typically compress about 3x with
+          // gzip. If the number of frames cannot accurately be calculated 
+          // use the max estimated file size to estimate # frames so that
+          // ptraj actions allocate enough memory.
+          tmpfsize = (long long int) frame_stat.st_size;
+          tmpfsize *= 4;
+          tmpfsize = (tmpfsize - file_size) / 4294967296LL;
+          maxi = (int) tmpfsize;
+          maxi++;
+          if (prnlev>1)
+            printf("\tLooking for uncompressed gzip size > 4GB, %i iterations.\n",maxi);
+          tmpfsize = 0;
+          sizeFound=0;
+          for (i = 0; i < maxi; i++ ) {
+            tmpfsize = (4294967296LL * i) + file_size;
+            if ( (tmpfsize % frame_size) == 0) {sizeFound=1; break;}
+          }
+          if (sizeFound) {
+            printf("Warning: Cannot accurately determine # of frames in gzipped trajectory %s.\n",
+                   filename);
+            printf("         This usually indicates the trajectory is corrupted.\n");
+            printf("         Ptraj will attempt to estimate the correct number of frames.\n");
+          }
+          file_size = tmpfsize; 
+          trajInfo->Nframes = (int) (file_size / frame_size);
+        }
+      }
+
       if (prnlev>0) fprintf(stdout,"    File has %i frames.\n",trajInfo->Nframes);
       if ( (file_size % frame_size) == 0 ) {
 	seekable = 1;
-	stop = trajInfo->Nframes;
       } else {
-	stop = -1;
 	seekable = 0;
 	fprintf(stderr, "%s: Could not predict number of frames for AMBER trajectory file: %s\n", ROUTINE, filename);
 	fprintf(stderr, "\tIf this is not a compressed file then there is a problem\n");
       }
+    stop = trajInfo->Nframes;
 
     actualAtoms = totalAtoms;
     //trajInfo->frameSize = frame_size;
@@ -2569,6 +2608,8 @@
   trajInfo->isBox = isBox;
   trajInfo->isVelocity = isVelocity;
   trajInfo->type = type;
+  // If compressed, no seek possible
+  if (trajInfo->compressType > 0) trajInfo->seekable=0;
 
   // This should eventually get its own structure
   if (type==COORD_CHARMM_TRAJECTORY) 
diff -urN amber11.orig/AmberTools/src/rism/amber_rism_interface.f amber11/AmberTools/src/rism/amber_rism_interface.f
--- amber11.orig/AmberTools/src/rism/amber_rism_interface.f	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/rism/amber_rism_interface.f	2011-10-25 15:01:28.241288520 +0300
@@ -815,7 +815,6 @@
         !redo calculation with charges off
         call rism3d_unsetCharges(rism_3d)
         call rism3d_solve(rism_3d,rismprm%saveprogress,rismprm%progress,rismprm%maxstep,rismprm%tolerance)
-        call rism3d_resetCharges(rism_3d)
 
         !setup memory space
         apol_exchem => apol_mpi_buffer(1:rism_3d%solv%natom) 
@@ -825,6 +824,7 @@
         apol_exchem = rism3d_exchem(rism_3d,rismprm%asympCorr)*KB*rism_3d%solv%temperature
         apol_exchemGF = rism3d_exchemGF(rism_3d,rismprm%asympCorr)*KB*rism_3d%solv%temperature
         
+        call rism3d_resetCharges(rism_3d)
         !parallel communication
 #ifdef MPI
 #  ifdef USE_MPI_IN_PLACE
diff -urN amber11.orig/AmberTools/src/rism/rism1d_potential_c.f amber11/AmberTools/src/rism/rism1d_potential_c.f
--- amber11.orig/AmberTools/src/rism/rism1d_potential_c.f	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/rism/rism1d_potential_c.f	2011-10-25 15:01:28.242288519 +0300
@@ -124,7 +124,7 @@
     type(solvMDL), intent(in) :: mdl
     _REAL_, intent(in) :: density
     integer :: oldnv
-    integer :: iv1, iv2, ivv, iv, iat, imlt
+    integer :: iv1, iv2, ivv, iv, iat, imlt, isp
 
     !increment scalar variables
     oldnv = this%nv
@@ -139,7 +139,10 @@
     this%nat(this%nsp) = mdl%ntype
     this%mta => safemem_realloc(this%mta, max(ubound(this%mta,1),mdl%ntype), this%nsp)
     this%mta(1:mdl%ntype,this%nsp) = mdl%multi 
-
+    !zero out multiplicity for unused indicies in previously add species
+    do isp=1, this%nsp
+       this%mta(this%nat(isp)+1:,isp)=0
+    end do
     this%mtv => safemem_realloc(this%mtv,this%nv)
     this%mtv(oldnv+1:this%nv) = mdl%multi
 
@@ -178,7 +181,7 @@
     this%rminv => safemem_realloc(this%rminv,this%nv)
     this%rminv(oldnv+1:this%nv) = mdl%rmin/2d0
 
-    this%rma => safemem_realloc(this%rma,3,ubound(this%mta,1),maxval(this%nat),this%nsp)
+    this%rma => safemem_realloc(this%rma,3,maxval(this%mta),maxval(this%nat),this%nsp,.true.,.false.)
     iv = 0
     do iat=1,this%nat(this%nsp)
        do imlt = 1, this%mta(iat,this%nsp)
@@ -186,7 +189,7 @@
           this%rma(:,imlt,iat,this%nsp) = mdl%coord(:,iv)
        end do
     end do
-    this%wlmvv => safemem_realloc(this%wlmvv,ubound(this%mta,1),this%nv,this%nv)
+    this%wlmvv => safemem_realloc(this%wlmvv,maxval(this%mta),this%nv,this%nv)
     call intramolecular_dist(this)
 
     !data arrays in the original 1D-RISM code had an offset of 0 in the first index (like C).
@@ -269,7 +272,7 @@
          r,rs, rs6,ri6, usr,usra
 
     _REAL_ ::  d0x(this%nv), d0y(this%nv), d1z(this%nv), &
-         wkvv(this%nv,this%nv)
+         wkvv(this%nv,this%nv), erfc_test
     _REAL_, external :: erfc
 
 
@@ -478,10 +481,21 @@
              r = (ir-1)*this%dr
              k = (ir-1)*this%dk
              qvv = charge*this%qspv(iv1)*this%qspv(iv2)
-             this%hlrvv(ir,ivv) = -qvv/this%dielconst &
-                  * 0.5d0 * exp((this%smear*this%kappa/2.d0)**2) &
-                  * ( exp(-this%kappa*r)*erfc(this%kappa*this%smear/2.d0 - r/this%smear) &
-                  - exp(this%kappa*r)*erfc(this%kappa*this%smear/2.d0 + r/this%smear) )
+             !for large grids with short Debye lengths the positive
+             !exponent can overflow.  erfc is already zero at this
+             !point.  So we test erfc to see if we can avoid the
+             !exponent
+             erfc_test = erfc(this%kappa*this%smear/2.d0 + r/this%smear)
+             if(erfc_test > sqrt(tiny(1d0)))then
+                this%hlrvv(ir,ivv) = -qvv/this%dielconst &
+                     * 0.5d0 * exp((this%smear*this%kappa/2.d0)**2) &
+                     * ( exp(-this%kappa*r)*erfc(this%kappa*this%smear/2.d0 - r/this%smear) &
+                     - exp(this%kappa*r)*erfc_test )
+             else
+                this%hlrvv(ir,ivv) = -qvv/this%dielconst &
+                     * 0.5d0 * exp((this%smear*this%kappa/2.d0)**2) &
+                     * ( exp(-this%kappa*r)*erfc(this%kappa*this%smear/2.d0 - r/this%smear))
+             end if
              this%hlkvv(ir,ivv) = -qvv/this%dielconst &
                   * 4.d0*pi*exp(-(0.5d0*this%smear*k)**2) * k/(k**2+this%kappa**2)
           enddo
diff -urN amber11.orig/AmberTools/src/rism/rism3d_c.f amber11/AmberTools/src/rism/rism3d_c.f
--- amber11.orig/AmberTools/src/rism/rism3d_c.f	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/rism/rism3d_c.f	2011-10-25 15:01:28.245288516 +0300
@@ -1086,26 +1086,26 @@
   !reallocate arrays that require preservation of their contents
 #if defined(MPI)
   this%cuvWRK => safemem_realloc(this%cuvWRK,this%grid%nr(1),this%grid%nr(2),this%grid%nr(3),&
-       this%solv%natom,this%NVec,.true.)
+       this%solv%natom,this%NVec,.true.,.true.)
   if(rism3d_solu_charged(this%solu))then
      this%oldcuvChg => safemem_realloc(this%oldcuvChg,this%grid%nr(1),this%grid%nr(2),&
-          this%grid%nr(3),this%solv%natom,this%ncuvsteps,.true.)
+          this%grid%nr(3),this%solv%natom,this%ncuvsteps,.true.,.true.)
      this%oldcuv => this%oldcuvChg
   else
      this%oldcuvNoChg => safemem_realloc(this%oldcuvNoChg,this%grid%nr(1),this%grid%nr(2),&
-          this%grid%nr(3),this%solv%natom,this%ncuvsteps,.true.)
+          this%grid%nr(3),this%solv%natom,this%ncuvsteps,.true.,.true.)
      this%oldcuv => this%oldcuvNoChg
   end if
 #else
   this%cuvWRK => safemem_realloc(this%cuvWRK,this%grid%nr(1),this%grid%nr(2),this%grid%nr(3),&
-       this%solv%natom,this%NVec,.true.)
+       this%solv%natom,this%NVec,.true.,.true.)
   if(rism3d_solu_charged(this%solu))then
      this%oldcuvChg => safemem_realloc(this%oldcuvChg,this%grid%nr(1),this%grid%nr(2),&
-          this%grid%nr(3),this%solv%natom,this%ncuvsteps,.true.)
+          this%grid%nr(3),this%solv%natom,this%ncuvsteps,.true.,.true.)
      this%oldcuv => this%oldcuvChg
   else
      this%oldcuvNoChg => safemem_realloc(this%oldcuvNoChg,this%grid%nr(1),this%grid%nr(2),&
-          this%grid%nr(3),this%solv%natom,this%ncuvsteps,.true.)
+          this%grid%nr(3),this%solv%natom,this%ncuvsteps,.true.,.true.)
      this%oldcuv => this%oldcuvNoChg
   end if
 !!$  this%oldcuv => safemem_realloc(this%oldcuv,this%grid%nr(1),this%grid%nr(2),&
diff -urN amber11.orig/AmberTools/src/rism/rism3d_opendx.f amber11/AmberTools/src/rism/rism3d_opendx.f
--- amber11.orig/AmberTools/src/rism/rism3d_opendx.f	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/rism/rism3d_opendx.f	2011-10-25 15:01:28.205288553 +0300
@@ -49,9 +49,11 @@
      module procedure readDXHeader_file, readDXHeader_unit
   end interface readDXHeader
 
+#if 0
   interface readDX
      module procedure readDX_3D,readDX_3D_data, readDX_1D, readDX_1D_data
   end interface readDX
+#endif
 contains
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !!!Reads in a OpenDX file header.  Expects
@@ -160,6 +162,7 @@
     end if
   end subroutine readDXHeader_unit
 
+#if 0
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !!!Reads in a OpenDX file, returning data in a pointer, allocating necessary memory.  Expects
 !!!a 3D, regularly spaced grid in ASCII format.
@@ -311,6 +314,7 @@
     call readDX_data(unit,data,ndata,npos)
     close(unit)
   end subroutine readDX_1D_data
+#endif
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !!!write to file in open DX format for use in VMD.  When writing in
diff -urN amber11.orig/AmberTools/src/rism/rism3d.snglpnt.nab amber11/AmberTools/src/rism/rism3d.snglpnt.nab
--- amber11.orig/AmberTools/src/rism/rism3d.snglpnt.nab	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/rism/rism3d.snglpnt.nab	2011-10-25 15:01:28.243288518 +0300
@@ -632,6 +632,7 @@
 mm_options(sprintf("centering=%d, zerofrc=%d, apply_rism_force=%d",rismOpt.centering,rismOpt.zerofrc,rismOpt.apply_rism_force));
 mm_options(sprintf("polarDecomp=%d",rismOpt.polarDecomp));
 mm_options(sprintf("ntwrism=%d, verbose=%d, progress=%d",rismOpt.ntwrism,rismOpt.verbose,rismOpt.progress));
+mm_options(sprintf("asympCorr=%d",rismOpt.asympcorr));
 mm_options(sprintf("saveprogress=%d",rismOpt.saveprogress));
 mme_init( m, NULL, "::Z", p_xyz, NULL);
 
diff -urN amber11.orig/AmberTools/src/rism/safemem.f amber11/AmberTools/src/rism/safemem.f
--- amber11.orig/AmberTools/src/rism/safemem.f	2011-04-14 15:30:19.000000000 +0300
+++ amber11/AmberTools/src/rism/safemem.f	2011-10-25 15:01:28.247288515 +0300
@@ -46,13 +46,13 @@
        !logical :: Current number of bytes of logical memory allocated
        !char    :: Current number of bytes of character memory allocated
        !total   :: Current number of bytes of total memory allocated
-       integer*8 :: int,real,logical,char,total
+       integer*8 :: int=0,real=0,logical=0,char=0,total=0
        !maxint     :: Current number of bytes of integer memory allocated
        !maxreal    :: Current number of bytes of real memory allocated
        !maxlogical :: Current number of bytes of logical memory allocated
        !maxchar    :: Current number of bytes of character memory allocated
        !max        :: Current number of bytes of total memory allocated
-       integer*8 :: maxint,maxreal,maxlogical,maxchar,max
+       integer*8 :: maxint=0,maxreal=0,maxlogical=0,maxchar=0,max=0
     end type memTracker
 
     !BYTES_PER_GIGABYTES :: used to convert between bytes and GB
@@ -352,6 +352,9 @@
 !!!   n4    :: size of the fourth dimension
 !!!   preserve :: boolean indicating whether or not to preserve the contents of 
 !!!           the array (optional)
+!!!   center :: when preserving the contents of the array, center the 
+!!!             data in the array instead of preserving the value at each
+!!!             index 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     FUNCTION safemem_realloc_4d_real(p, n1, n2, n3, n4, preserve, center)
       implicit none
@@ -369,7 +372,7 @@
 #endif /*RISM_DEBUG*/
       prsrv = .true.
       if(present(preserve)) prsrv=preserve
-      cntr = .true.
+      cntr = .false.
       if(present(center)) cntr=center
 
       if(.not.prsrv .and. associated(p)) then
@@ -499,6 +502,9 @@
 !!!   n5    :: size of the fifth dimension
 !!!   preserve :: boolean indicating whether or not to preserve the contents of 
 !!!           the array (optional)
+!!!   center :: when preserving the contents of the array, center the 
+!!!             data in the array instead of preserving the value at each
+!!!             index 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     FUNCTION safemem_realloc_5d_real(p, n1, n2, n3, n4, n5, preserve, center)
       implicit none
@@ -516,7 +522,7 @@
 #endif /*RISM_DEBUG*/
       prsrv = .true.
       if(present(preserve)) prsrv = preserve
-      cntr=.true.
+      cntr=.false.
       if(present(center)) cntr = center
 
       if(.not.prsrv .and. associated(p)) then
@@ -1006,7 +1012,7 @@
       !work around for old gfortran bug
       !  if(associated(p)) deallocate(p,STAT=safemem_dealloc_pointer_1d_logical)
       if(associated(p))then
-         call memadd_c(totalmem,-product(ubound(p))*kind(p))
+         call memadd_l(totalmem,-product(ubound(p))*kind(p))
          deallocate(p,STAT=temp)
       end if
       safemem_dealloc_pointer_1d_logical = temp
diff -urN amber11.orig/AmberTools/src/sqm/qm2_energy.f amber11/AmberTools/src/sqm/qm2_energy.f
--- amber11.orig/AmberTools/src/sqm/qm2_energy.f	2011-03-11 20:43:13.000000000 +0200
+++ amber11/AmberTools/src/sqm/qm2_energy.f	2011-10-25 15:01:28.206288552 +0300
@@ -277,7 +277,7 @@
 
       ! Add PM6 corrections to Heat of Formation
       if (qmmm_nml%qmtheory%PM6) then
-         escf = escf + pm6_correction()
+         escf = escf + hofCorrection()
       end if
 
       call timer_stop(TIME_QMMMENERGYSCF)
diff -urN amber11.orig/AmberTools/src/sqm/qm2_get_qm_forces.f amber11/AmberTools/src/sqm/qm2_get_qm_forces.f
--- amber11.orig/AmberTools/src/sqm/qm2_get_qm_forces.f	2011-03-11 20:43:13.000000000 +0200
+++ amber11/AmberTools/src/sqm/qm2_get_qm_forces.f	2011-10-25 15:01:28.208288550 +0300
@@ -250,7 +250,7 @@
    ! --------------------------------------------
    if (qmmm_nml%qmtheory%PM6) then
       natom = qmmm_struct%nquant_nlink
-      call pm6_correction(natom, dxyzqm)
+      call hofCorrectionGradient(natom, dxyzqm)
    end if
 
    if(qmmm_nml%peptide_corr) then
diff -urN amber11.orig/AmberTools/src/sqm/qm2_pm6_hof_module.f amber11/AmberTools/src/sqm/qm2_pm6_hof_module.f
--- amber11.orig/AmberTools/src/sqm/qm2_pm6_hof_module.f	2011-03-11 20:43:13.000000000 +0200
+++ amber11/AmberTools/src/sqm/qm2_pm6_hof_module.f	2011-10-25 15:01:28.209288549 +0300
@@ -21,8 +21,7 @@
   implicit none
 
   private
-  public :: pm6_correction
-  public :: corInfoType, print
+  public :: corInfoType, print, hofCorrection, hofCorrectionGradient
   public :: cct, nsp2
   public :: strlen
 
@@ -30,11 +29,6 @@
      module procedure printCorInfoType
   end interface
 
-  interface pm6_correction
-     module procedure hofCorrection
-     module procedure hofCorrectionGradient
-  end interface
-
   ! Data type collecting information on PM6 HOF corrections
   type corInfoType
      logical :: inUse  ! correction in use ?
diff -urN amber11.orig/AmberTools/test/cpptraj/Test_General/RunTest.sh amber11/AmberTools/test/cpptraj/Test_General/RunTest.sh
--- amber11.orig/AmberTools/test/cpptraj/Test_General/RunTest.sh	2011-04-14 15:30:21.000000000 +0300
+++ amber11/AmberTools/test/cpptraj/Test_General/RunTest.sh	2011-10-25 15:01:28.215288544 +0300
@@ -25,7 +25,7 @@
 DoTest PhiPsi.dat.save PhiPsi.dat
 DoTest test.crd.save test.crd
 DoTest a1.dat.save a1.dat
-DoTest test.rst7.103.save Restart/test.rst7.103
+DoTest test.rst7.103.save Restart/test.rst7.123
 DoTest test.nc.save test.nc
 DoTest r4.dat.save r4.dat
 DoTest a2.dat.gz.save a2.dat.gz
diff -urN amber11.orig/AmberTools/test/mmpbsa_py/11_3D-RISM/FINAL_RESULTS_MMPBSA.dat.save amber11/AmberTools/test/mmpbsa_py/11_3D-RISM/FINAL_RESULTS_MMPBSA.dat.save
--- amber11.orig/AmberTools/test/mmpbsa_py/11_3D-RISM/FINAL_RESULTS_MMPBSA.dat.save	2011-04-14 15:30:22.000000000 +0300
+++ amber11/AmberTools/test/mmpbsa_py/11_3D-RISM/FINAL_RESULTS_MMPBSA.dat.save	2011-10-25 15:01:28.247288515 +0300
@@ -1,4 +1,4 @@
-| Run on Tue Mar  8 15:33:18 PST 2011
+| Run on Fri Oct  7 17:12:46 EDT 2011
 
 |Input file:
 |--------------------------------------------------------------
@@ -32,14 +32,14 @@
 -------------------------------------------------------------------------------
 VDWAALS                     -4.6380                0.3291              0.2327
 EEL                       -425.3449                4.5554              3.2212
-ERISM                     -164.0501                3.9611              2.8009
-   POLAR                  -219.8772                4.0588              2.8700
-   APOLAR                   55.8271                0.0977              0.0691
+ERISM                     -164.0499                3.9609              2.8008
+   POLAR                  -235.0781                4.4994              3.1816
+   APOLAR                   71.0282                0.5386              0.3808
 
 G gas                     -429.9829                4.2263              2.9885
-G solv                    -164.0501                3.9611              2.8009
+G solv                    -164.0499                3.9609              2.8008
 
-TOTAL                     -594.0331                0.2653              0.1876
+TOTAL                     -594.0329                0.2655              0.1877
 
 
 Receptor:
@@ -48,8 +48,8 @@
 VDWAALS                     -3.9302                0.2702              0.1910
 EEL                       -254.1833                4.5196              3.1959
 ERISM                      -79.2939                3.0131              2.1306
-   POLAR                  -118.9799                3.1556              2.2314
-   APOLAR                   39.6860                0.1425              0.1008
+   POLAR                  -126.9784                3.4713              2.4546
+   APOLAR                   47.6845                0.4582              0.3240
 
 G gas                     -258.1136                4.2494              3.0048
 G solv                     -79.2939                3.0131              2.1306
@@ -62,12 +62,12 @@
 -------------------------------------------------------------------------------
 VDWAALS                     -0.7056                0.0606              0.0428
 EEL                       -170.5448                1.1864              0.8389
-ERISM                      -85.2510                0.0719              0.0509
-   POLAR                  -101.3724                0.0489              0.0346
-   APOLAR                   16.1214                0.0230              0.0163
+ERISM                      -85.2510                0.0719              0.0508
+   POLAR                  -108.6574                0.0351              0.0249
+   APOLAR                   23.4064                0.1070              0.0757
 
 G gas                     -171.2505                1.2470              0.8818
-G solv                     -85.2510                0.0719              0.0509
+G solv                     -85.2510                0.0719              0.0508
 
 TOTAL                     -256.5015                1.1751              0.8309
 
@@ -77,15 +77,15 @@
 -------------------------------------------------------------------------------
 VDWAALS                     -0.0021                0.0017              0.0012
 EEL                         -0.6167                1.2222              0.8642
-ERISM                        0.4947                1.0198              0.7211
-   POLAR                     0.4750                0.9520              0.6732
-   APOLAR                    0.0198                0.0678              0.0480
+ERISM                        0.4950                1.0196              0.7210
+   POLAR                     0.5577                0.9929              0.7021
+   APOLAR                   -0.0627                0.0267              0.0189
 
 DELTA G gas                 -0.6189                1.2239              0.8654
-DELTA G solv                 0.4947                1.0198              0.7211
+DELTA G solv                 0.4950                1.0196              0.7210
 
 
- DELTA G binding =             -0.1241 +/-      0.2041                 0.1443
+ DELTA G binding =             -0.1239 +/-      0.2043                 0.1445
 
 
 -------------------------------------------------------------------------------
@@ -99,8 +99,8 @@
 VDWAALS                     -4.6380                0.3291              0.2327
 EEL                       -425.3449                4.5554              3.2212
 ERISM                     -187.9280                4.0576              2.8691
-   POLAR                  -221.3631                4.0723              2.8795
-   APOLAR                   33.4351                0.0147              0.0104
+   POLAR                  -236.5648                4.5137              3.1916
+   APOLAR                   48.6367                0.4561              0.3225
 
 G gas                     -429.9829                4.2263              2.9885
 G solv                    -187.9280                4.0576              2.8691
@@ -113,12 +113,12 @@
 -------------------------------------------------------------------------------
 VDWAALS                     -3.9302                0.2702              0.1910
 EEL                       -254.1833                4.5196              3.1959
-ERISM                      -94.4232                3.0803              2.1781
-   POLAR                  -119.8020                3.1352              2.2169
-   APOLAR                   25.3788                0.0549              0.0388
+ERISM                      -94.4233                3.0804              2.1781
+   POLAR                  -127.8003                3.4511              2.4403
+   APOLAR                   33.3771                0.3707              0.2621
 
 G gas                     -258.1136                4.2494              3.0048
-G solv                     -94.4232                3.0803              2.1781
+G solv                     -94.4233                3.0804              2.1781
 
 TOTAL                     -352.5368                1.1691              0.8267
 
@@ -128,14 +128,14 @@
 -------------------------------------------------------------------------------
 VDWAALS                     -0.7056                0.0606              0.0428
 EEL                       -170.5448                1.1864              0.8389
-ERISM                      -94.0188                0.0538              0.0381
-   POLAR                  -102.0695                0.0274              0.0194
-   APOLAR                    8.0506                0.0264              0.0187
+ERISM                      -94.0185                0.0541              0.0383
+   POLAR                  -109.3544                0.0565              0.0399
+   APOLAR                   15.3358                0.1106              0.0782
 
 G gas                     -171.2505                1.2470              0.8818
-G solv                     -94.0188                0.0538              0.0381
+G solv                     -94.0185                0.0541              0.0383
 
-TOTAL                     -265.2693                1.1932              0.8437
+TOTAL                     -265.2690                1.1929              0.8435
 
 
 Differences (Complex - Receptor - Ligand):
@@ -143,15 +143,15 @@
 -------------------------------------------------------------------------------
 VDWAALS                     -0.0021                0.0017              0.0012
 EEL                         -0.6167                1.2222              0.8642
-ERISM                        0.5140                1.0311              0.7291
-   POLAR                     0.5083                0.9645              0.6820
-   APOLAR                    0.0057                0.0666              0.0471
+ERISM                        0.5137                1.0314              0.7293
+   POLAR                     0.5900                1.0061              0.7114
+   APOLAR                   -0.0762                0.0253              0.0179
 
 DELTA G gas                 -0.6189                1.2239              0.8654
-DELTA G solv                 0.5140                1.0311              0.7291
+DELTA G solv                 0.5137                1.0314              0.7293
 
 
- DELTA G binding =             -0.1049 +/-      0.1928                 0.1363
+ DELTA G binding =             -0.1051 +/-      0.1926                 0.1362
 
 
 -------------------------------------------------------------------------------
diff -urN amber11.orig/AmberTools/test/nab/rism3d.snglpnt.2.out.check amber11/AmberTools/test/nab/rism3d.snglpnt.2.out.check
--- amber11.orig/AmberTools/test/nab/rism3d.snglpnt.2.out.check	2011-04-14 15:30:23.000000000 +0300
+++ amber11/AmberTools/test/nab/rism3d.snglpnt.2.out.check	2011-10-25 15:01:28.248288514 +0300
@@ -32,6 +32,7 @@
 	mm_options:  ntwrism=1
 	mm_options:  verbose=0
 	mm_options:  progress=0
+	mm_options:  asympCorr=1
 	mm_options:  saveprogress=0
 |3D-RISM thermodynamic data key
 |solute_epot [kcal/mol] :            Total               LJ          Coulomb             Bond            Angle         Dihedral           H-Bond            LJ-14       Coulomb-14       Restraints          3D-RISM
@@ -74,13 +75,13 @@
 3D-RISM processing complete.
 
 |Timing summary:
-|              Initialize       0.042
+|              Initialize       0.046
 |             Molec. Dyn.       0.000
 |             Normal Mode       0.000
 |             Conj. Grad.       0.000
 |                  Newton       0.000
 |-------------------------
-|                   Total       0.042
+|                   Total       0.046
 
 |1st derivative timing summary:
 |             constraints       0.000
@@ -91,7 +92,7 @@
 |                 nonbond       0.000
 |               gen. Born       0.000
 |       Poisson Boltzmann       0.000
-|                 3D-RISM      10.167
+|                 3D-RISM       8.211
 |                   Other       0.000
 |-------------------------
-|                   Total      10.167
+|                   Total       8.212
diff -urN amber11.orig/AmberTools/test/nab/rism3d.snglpnt.out.check amber11/AmberTools/test/nab/rism3d.snglpnt.out.check
--- amber11.orig/AmberTools/test/nab/rism3d.snglpnt.out.check	2011-04-14 15:30:23.000000000 +0300
+++ amber11/AmberTools/test/nab/rism3d.snglpnt.out.check	2011-10-25 15:01:28.248288514 +0300
@@ -31,6 +31,7 @@
 	mm_options:  ntwrism=0
 	mm_options:  verbose=0
 	mm_options:  progress=0
+	mm_options:  asympCorr=1
 	mm_options:  saveprogress=0
 |3D-RISM thermodynamic data key
 |solute_epot [kcal/mol] :            Total               LJ          Coulomb             Bond            Angle         Dihedral           H-Bond            LJ-14       Coulomb-14       Restraints          3D-RISM
@@ -55,10 +56,10 @@
 rism_volume:  1.93595981E+002
 rism_exNumb:                  -6.38184158E+000 -1.27637588E+001
 rism_exChrg: -3.20562831E-005  5.40924893E+000 -5.40928099E+000
-rism_polar_: -1.31661477E+001 -4.40204657E+001  3.08543179E+001
-rism_apolar:  2.96543934E+001  7.56776450E+001 -4.60232516E+001
-rism_polGF_: -1.34197324E+001 -4.39508092E+001  3.05310768E+001
-rism_apolGF:  1.97398606E+001  7.11960080E+001 -5.14561474E+001
+rism_polar_: -1.47850626E+001 -1.09412958E+001 -3.84376682E+000
+rism_apolar:  3.12733083E+001  4.25984751E+001 -1.13251668E+001
+rism_polGF_: -1.50386472E+001 -1.08716393E+001 -4.16700794E+000
+rism_apolGF:  2.13587755E+001  3.81168382E+001 -1.67580627E+001
 
 Frame: 2 of 3
 solute_epot: -3.41386230E-001  2.56854615E+000 -8.23476129E+001  3.38717466E-002  3.59735615E-001  7.49048012E+000  0.00000000E+000  4.97044290E+000  5.01391318E+001  0.00000000E+000  1.64440184E+001
@@ -68,10 +69,10 @@
 rism_volume:  1.93535504E+002
 rism_exNumb:                  -6.37993323E+000 -1.27596468E+001
 rism_exChrg:  9.31177385E-005  5.40763142E+000 -5.40753830E+000
-rism_polar_: -1.31967073E+001 -4.40467251E+001  3.08500178E+001
-rism_apolar:  2.96407256E+001  7.56851573E+001 -4.60444317E+001
-rism_polGF_: -1.34505678E+001 -4.39769309E+001  3.05263631E+001
-rism_apolGF:  1.97272712E+001  7.12038497E+001 -5.14765785E+001
+rism_polar_: -1.48191496E+001 -1.09491800E+001 -3.86996959E+000
+rism_apolar:  3.12631679E+001  4.25876122E+001 -1.13244443E+001
+rism_polGF_: -1.50730101E+001 -1.08793858E+001 -4.19362428E+000
+rism_apolGF:  2.13497135E+001  3.81063046E+001 -1.67565911E+001
 
 Frame: 3 of 3
 solute_epot: -6.77945271E-001  2.31243593E+000 -8.22812685E+001  9.08980189E-002  3.84286510E-001  7.48894041E+000  0.00000000E+000  4.91668330E+000  5.00274224E+001  0.00000000E+000  1.63826567E+001
@@ -81,21 +82,21 @@
 rism_volume:  1.93468855E+002
 rism_exNumb:                  -6.37771162E+000 -1.27552065E+001
 rism_exChrg:  9.18518609E-005  5.40574837E+000 -5.40565652E+000
-rism_polar_: -1.32423609E+001 -4.40992117E+001  3.08568508E+001
-rism_apolar:  2.96250176E+001  7.57232232E+001 -4.60982056E+001
-rism_polGF_: -1.34968274E+001 -4.40292606E+001  3.05324332E+001
-rism_apolGF:  1.97126459E+001  7.12421943E+001 -5.15295484E+001
+rism_polar_: -1.48691739E+001 -1.09507135E+001 -3.91846037E+000
+rism_apolar:  3.12518306E+001  4.25747250E+001 -1.13228944E+001
+rism_polGF_: -1.51236404E+001 -1.08807624E+001 -4.24287800E+000
+rism_apolGF:  2.13394589E+001  3.80936961E+001 -1.67542372E+001
 
 3D-RISM processing complete.
 
 |Timing summary:
-|              Initialize       0.043
+|              Initialize       0.047
 |             Molec. Dyn.       0.000
 |             Normal Mode       0.000
 |             Conj. Grad.       0.000
 |                  Newton       0.000
 |-------------------------
-|                   Total       0.043
+|                   Total       0.047
 
 |1st derivative timing summary:
 |             constraints       0.000
@@ -106,7 +107,7 @@
 |                 nonbond       0.000
 |               gen. Born       0.000
 |       Poisson Boltzmann       0.000
-|                 3D-RISM      32.639
+|                 3D-RISM      30.135
 |                   Other       0.000
 |-------------------------
-|                   Total      32.639
+|                   Total      30.135
diff -urN amber11.orig/AmberTools/test/nab/Run.prm amber11/AmberTools/test/nab/Run.prm
--- amber11.orig/AmberTools/test/nab/Run.prm	2011-04-14 15:30:23.000000000 +0300
+++ amber11/AmberTools/test/nab/Run.prm	2011-10-25 15:01:28.133288619 +0300
@@ -17,7 +17,7 @@
 
 echo "checking the prmtop file:"
 echo ""
-tail -3209 tprmtop > tprmtop1
+tail -3228 tprmtop > tprmtop1
 ../dacdif tprmtop.check tprmtop1
 
 rm -f prm prm.c tleap.out leap.log tprmcrd prm.out1 tprmtop
diff -urN amber11.orig/AmberTools/test/nab/tprmtop.check amber11/AmberTools/test/nab/tprmtop.check
--- amber11.orig/AmberTools/test/nab/tprmtop.check	2011-03-10 20:12:18.000000000 +0200
+++ amber11/AmberTools/test/nab/tprmtop.check	2011-10-25 15:01:28.135288617 +0300
@@ -1,3 +1,4 @@
+%VERSION  VERSION_STAMP = V0001.000  DATE = 05/09/11  12:59:19                  
 %FLAG TITLE                                                                     
 %FORMAT(20a4)                                                                   
                                                                                 
@@ -541,6 +542,24 @@
   3.14159400E+00  3.14159400E+00  3.14159400E+00  3.14159400E+00  3.14159400E+00
   3.14159400E+00  3.14159400E+00  3.14159400E+00  3.14159400E+00  3.14159400E+00
   3.14159400E+00  3.14159400E+00  3.14159400E+00
+%FLAG SCEE_SCALE_FACTOR                                                         
+%FORMAT(5E16.8)                                                                 
+  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00
+  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00
+  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00
+  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00
+  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00
+  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00  1.20000000E+00
+  0.00000000E+00  0.00000000E+00  0.00000000E+00
+%FLAG SCNB_SCALE_FACTOR                                                         
+%FORMAT(5E16.8)                                                                 
+  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00
+  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00
+  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00
+  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00
+  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00
+  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00  2.00000000E+00
+  0.00000000E+00  0.00000000E+00  0.00000000E+00
 %FLAG SOLTY                                                                     
 %FORMAT(5E16.8)                                                                 
   0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00
diff -urN amber11.orig/AmberTools/test/rism1d/check1d amber11/AmberTools/test/rism1d/check1d
--- amber11.orig/AmberTools/test/rism1d/check1d	2011-04-14 15:30:29.000000000 +0300
+++ amber11/AmberTools/test/rism1d/check1d	2011-10-25 15:01:28.249288513 +0300
@@ -85,7 +85,7 @@
 #It is unrealistic to achieve low relative error for these very small number so we only 
 #use the abolute error
 if [ -s $1.bvv.save ]; then
-   $AMBERHOME/AmberTools/test/dacdif -a 1.e-7 $1.bvv.save $1.bvv
+   $AMBERHOME/AmberTools/test/dacdif -a 2.e-7 $1.bvv.save $1.bvv
 fi
 
 /bin/rm -f $1.xvv.delhv0 $1.xvv.delhv0.save $1.xvv.xvv $1.xvv.xvv.save\
diff -urN amber11.orig/AT15_Amber11.py amber11/AT15_Amber11.py
--- amber11.orig/AT15_Amber11.py	2011-04-14 15:30:11.000000000 +0300
+++ amber11/AT15_Amber11.py	2011-10-25 15:01:28.221288538 +0300
@@ -145,4 +145,29 @@
 makefile.close()
       
 # Now we are done
-print "\nAmber 11 patched for AmberTools 1.5. Run\nmake %s\nto build amber11\n" % buildtype
+print "\nAmber 11 patched for AmberTools 1.5. Run\ncd src; make %s\nto build amber11\n" % buildtype
+
+# Now print out details about expected test FAILUREs and
+# errors:
+
+warning = """NOTE: Because PBSA has changed since Amber 11 was released, some
+tests are known to fail and others are known to quit in error. These
+can be safely ignored.
+
+Tests that error: Tests in $AMBERHOME/test/sander_pbsa_frc
+   Run.argasp.min    Run.dadt.min      Run.dgdc.min
+   Run.lysasp.min    Run.polyALA.min   Run.polyAT.min
+   Run.argasp.min    Run.dadt.min      Run.dgdc.min
+   Run.lysasp.min    Run.polyALA.min   Run.polyAT.min
+   Run.argasp.min    Run.dadt.min      Run.dgdc.min
+   Run.lysasp.min    Run.polyALA.min   Run.polyAT.min
+
+Tests that produce possible FAILUREs:
+   cd sander_pbsa_ipb2   && ./Run.110D.min
+   cd sander_pbsa_lpb    && ./Run.lsolver.min (only some of them fail here)
+   cd sander_pbsa_tsr    && ./Run.tsrb.min
+   cd sander_pbsa_decres && ./Run.pbsa_decres
+   mm_pbsa.pl tests 02, 03, and 05
+"""
+
+print warning
diff -urN amber11.orig/dat/antechamber/ATOMTYPE_AMBER.DEF amber11/dat/antechamber/ATOMTYPE_AMBER.DEF
--- amber11.orig/dat/antechamber/ATOMTYPE_AMBER.DEF	2011-04-14 15:30:40.000000000 +0300
+++ amber11/dat/antechamber/ATOMTYPE_AMBER.DEF	2011-10-25 15:01:28.198288560 +0300
@@ -49,7 +49,7 @@
 ATD  F     *   9   1   &
 ATD  Cl    *   17  1   &
 ATD  Br    *   35  1   &
-ATD  F     *   53  1   &
+ATD  I     *   53  1   &
 ATD  P     *   15  &
 ATD  N1    *   7   1   &   
 ATD  NB    *   7   2   *   *   [RG5,AR1.AR2.AR3]         & 
diff -urN amber11.orig/dat/leap/cmd/leaprc.ff99SBnmr amber11/dat/leap/cmd/leaprc.ff99SBnmr
--- amber11.orig/dat/leap/cmd/leaprc.ff99SBnmr	2011-04-14 15:30:40.000000000 +0300
+++ amber11/dat/leap/cmd/leaprc.ff99SBnmr	2011-10-25 15:01:28.239288522 +0300
@@ -74,13 +74,6 @@
 	{ "OL"  "O" "sp3" }
 	{ "AC"  "C" "sp3" }
 	{ "EC"  "C" "sp3" }
-#ildn
-	{ "C3"  "C" "sp3" }
-	{ "C4"  "C" "sp3" }
-	{ "C5"   "C" "sp2" }
-	{ "C6"   "C" "sp2" }
-	{ "NP"   "N" "sp2" }
-	{ "OM"   "O" "sp2" } # guess!!!
 }
 #
 #	Load the main parameter set.
@@ -95,9 +88,9 @@
 #	Load main chain and terminating 
 #	amino acid libraries (i.e. ff94 libs)
 #
-loadOff all_amino94ildn.lib
-loadOff all_aminoct94ildn.lib
-loadOff all_aminont94ildn.lib
+loadOff all_amino94.lib
+loadOff all_aminoct94.lib
+loadOff all_aminont94.lib
 #
 #       Load water and ions
 # 
diff -urN amber11.orig/dat/leap/parm/parm10.dat amber11/dat/leap/parm/parm10.dat
--- amber11.orig/dat/leap/parm/parm10.dat	2011-04-14 15:30:40.000000000 +0300
+++ amber11/dat/leap/parm/parm10.dat	2011-10-25 15:01:28.218288541 +0300
@@ -783,8 +783,10 @@
 OS-P -OS-CT   1    0.25          0.0            -3.         JCC,7,(1986),230
 OS-P -OS-CT   1    1.20          0.0             2.         gg&gt ene.631g*/mp2
 H1-CT-C -O    1    0.80          0.0            -1.         Junmei et al, 1999
+H1-CT-C -O    1    0.00          0.0            -2.         Explicit of wild card X-C-CT-X
 H1-CT-C -O    1    0.08        180.0             3.         Junmei et al, 1999
 H1-CX-C -O    1    0.80          0.0            -1.         Junmei et al, 1999 (was H1-CT-C -O )
+H1-CX-C -O    1    0.00          0.0            -2.         Explicit of wild card X-C-CT-X
 H1-CX-C -O    1    0.08        180.0             3.         Junmei et al, 1999 (was H1-CT-C -O )
 HC-CT-C -O    1    0.80          0.0            -1.         Junmei et al, 1999
 HC-CT-C -O    1    0.00          0.0            -2.         Explicit of wild card X-C-CT-X
diff -urN amber11.orig/dat/leap/parm/parm99.dat amber11/dat/leap/parm/parm99.dat
--- amber11.orig/dat/leap/parm/parm99.dat	2011-04-14 15:30:40.000000000 +0300
+++ amber11/dat/leap/parm/parm99.dat	2011-10-25 15:01:28.221288538 +0300
@@ -546,7 +546,7 @@
 OS-P -OS-CT   1    0.25          0.0            -3.         JCC,7,(1986),230
 OS-P -OS-CT   1    1.20          0.0             2.         gg&gt ene.631g*/mp2
 H1-CT-C -O    1    0.80          0.0            -1.         Junmei et al, 1999
-HC-CT-C -O    1    0.00          0.0            -2.         Explicit of wild card X-C-CT-X
+H1-CT-C -O    1    0.00          0.0            -2.         Explicit of wild card X-C-CT-X
 H1-CT-C -O    1    0.08        180.0             3.         Junmei et al, 1999
 HC-CT-C -O    1    0.80          0.0            -1.         Junmei et al, 1999
 HC-CT-C -O    1    0.00          0.0            -2.         Explicit of wild card X-C-CT-X