File: PyMOL.c

package info (click to toggle)
pymol 0.98%2B0.99rc6-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,996 kB
  • ctags: 17,409
  • sloc: ansic: 206,868; python: 51,428; sh: 743; makefile: 382; csh: 21
file content (3049 lines) | stat: -rw-r--r-- 86,659 bytes parent folder | download
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
/* 
   A* -------------------------------------------------------------------
   B* This file contains source code for the PyMOL computer program
   C* copyright 1998-2000 by Warrn Lyford Delano of DeLano Scientific. 
   D* -------------------------------------------------------------------
   E* It is unlawful to modify or remove this copyright notice.
   F* -------------------------------------------------------------------
   G* Please see the accompanying LICENSE file for further information. 
   H* -------------------------------------------------------------------
   I* Additional authors of this source file include:
   -* 
   -* 
   -*
   Z* -------------------------------------------------------------------
*/

#include "os_std.h"
#include "os_gl.h"

#include "MemoryDebug.h"

#include "Base.h"

#include "OVContext.h"

#include "MemoryDebug.h"
#include "MemoryCache.h"
#include "Err.h"
#include "Util.h"
#include "Selector.h"
#include "Color.h"
#include "Ortho.h"
#include "Scene.h"
#include "PyMOLObject.h"
#include "Executive.h"
#include "Word.h"
#include "RepMesh.h"
#include "ObjectMolecule.h"
#include "Control.h"
#include "Sphere.h"
#include "Setting.h"
#include "Ray.h"
#include "Util.h"
#include "Movie.h"
#include "P.h"
#include "Editor.h"
#include "SculptCache.h"
#include "Isosurf.h"
#include "Tetsurf.h"
#include "PConv.h"
#include "VFont.h"
#include "Wizard.h"
#include "Text.h"
#include "Character.h"
#include "Seq.h"
#include "Seeker.h"
#include "Texture.h"
#include "TestPyMOL.h"
#include "TypeFace.h"

#include "PyMOL.h"
#include "PyMOLGlobals.h"
#include "PyMOLOptions.h"

#ifndef _PYMOL_NOPY
PyMOLGlobals *TempPyMOLGlobals = NULL;
#endif

/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifndef _PYMOL_NOPY
#ifdef _MACPYMOL_XCODE
extern int *MacPyMOLReady;
extern CPyMOLOptions *MacPyMOLOption;
#endif
#endif
/* END PROPRIETARY CODE SEGMENT */

#ifdef _MACPYMOL_XCODE
/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#define PYMOL_API_LOCK if((I->PythonInitStage)&&PLockAPIAsGlut(true)) {
#define PYMOL_API_UNLOCK PUnlockAPIAsGlut(); }
#define PYMOL_API_UNLOCK_NO_FLUSH PUnlockAPIAsGlutNoFlush(); }
/* END PROPRIETARY CODE SEGMENT */
#else 
#define PYMOL_API_LOCK {
#define PYMOL_API_UNLOCK }
#define PYMOL_API_UNLOCK_NO_FLUSH }
#endif

#define IDLE_AND_READY 10

typedef struct _CPyMOL {
  PyMOLGlobals *G;
  int FakeDragFlag;
  int RedisplayFlag;
  int PassiveFlag;
  int SwapFlag;
  int BusyFlag;
  int InterruptFlag; 
  int ReshapeFlag;
  int ClickReadyFlag;
  char ClickedObject[ObjNameMax];  
  int ClickedIndex;
  int DraggedFlag;
  int Reshape[PYMOL_RESHAPE_SIZE];
  int Progress[PYMOL_PROGRESS_SIZE];
  int ProgressChanged;
  int IdleAndReady;
  int ExpireCount;
  PyMOLSwapBuffersFn *SwapFn;

/* Python stuff */
#ifndef _PYMOL_NOPY
  int PythonInitStage;
#endif
  /* dynamically mapped string constants */

  OVLexicon *Lex;
  ov_word lex_pdb, lex_mol2, lex_mol, lex_sdf, lex_xplor, lex_ccp4;
  ov_word lex_string, lex_filename, lex_raw;

  OVOneToOne *Rep;
  ov_word lex_everything, lex_sticks, lex_spheres, lex_surface;
  ov_word lex_labels, lex_nb_spheres, lex_cartoon, lex_ribbon;
  ov_word lex_lines, lex_mesh, lex_dots, lex_dashes, lex_nonbonded;
  ov_word lex_cell, lex_cgo, lex_callback, lex_extent, lex_slice;

  OVOneToOne *Clip;  
  ov_word lex_near, lex_far, lex_move, lex_slab, lex_atoms;

  OVOneToOne *SelectList;
  ov_word lex_index, lex_id, lex_rank;

  OVOneToOne *Setting;
  ov_word lex_bonding_vdw_cutoff;
  ov_word lex_min_mesh_spacing;
  ov_word lex_dot_density;
  ov_word lex_dot_mode;
  ov_word lex_solvent_radius;
  ov_word lex_sel_counter;
  ov_word lex_bg_rgb;
  ov_word lex_ambient;
  ov_word lex_direct;
  ov_word lex_reflect;
  ov_word lex_light;
  ov_word lex_power;
  ov_word lex_antialias;
  ov_word lex_cavity_cull;
  ov_word lex_gl_ambient;
  ov_word lex_single_image;
  ov_word lex_movie_delay;
  ov_word lex_ribbon_power;
  ov_word lex_ribbon_power_b;
  ov_word lex_ribbon_sampling;
  ov_word lex_ribbon_radius;
  ov_word lex_stick_radius;
  ov_word lex_hash_max;
  ov_word lex_ortho;
  ov_word lex_spec_reflect;
  ov_word lex_spec_power;
  ov_word lex_sweep_angle;
  ov_word lex_sweep_speed;
  ov_word lex_dot_hydrogens;
  ov_word lex_dot_radius;
  ov_word lex_ray_trace_frames;
  ov_word lex_cache_frames;
  ov_word lex_trim_dots;
  ov_word lex_cull_spheres;
  ov_word lex_test1;
  ov_word lex_test2;
  ov_word lex_surface_best;
  ov_word lex_surface_normal;
  ov_word lex_surface_quality;
  ov_word lex_surface_proximity;
  ov_word lex_normal_workaround;
  ov_word lex_stereo_angle;
  ov_word lex_stereo_shift;
  ov_word lex_line_smooth;
  ov_word lex_line_width;
  ov_word lex_half_bonds;
  ov_word lex_stick_quality;
  ov_word lex_stick_overlap;
  ov_word lex_stick_nub;
  ov_word lex_all_states;
  ov_word lex_pickable;
  ov_word lex_auto_show_lines;
  ov_word lex_idle_delay;
  ov_word lex_no_idle;
  ov_word lex_fast_idle;
  ov_word lex_slow_idle;
  ov_word lex_rock_delay;
  ov_word lex_dist_counter;
  ov_word lex_dash_length;
  ov_word lex_dash_gap;
  ov_word lex_auto_zoom;
  ov_word lex_overlay;
  ov_word lex_text;
  ov_word lex_button_mode;
  ov_word lex_valence;
  ov_word lex_nonbonded_size;
  ov_word lex_label_color;
  ov_word lex_ray_trace_fog;
  ov_word lex_spheroid_scale;
  ov_word lex_ray_trace_fog_start;
  ov_word lex_spheroid_smooth;
  ov_word lex_spheroid_fill;
  ov_word lex_auto_show_nonbonded;
  ov_word lex_cache_display;
  ov_word lex_mesh_radius;
  ov_word lex_backface_cull;
  ov_word lex_gamma;
  ov_word lex_dot_width;
  ov_word lex_auto_show_selections;
  ov_word lex_auto_hide_selections;
  ov_word lex_selection_width;
  ov_word lex_selection_overlay;
  ov_word lex_static_singletons;
  ov_word lex_max_triangles;
  ov_word lex_depth_cue;
  ov_word lex_specular;
  ov_word lex_shininess;
  ov_word lex_sphere_quality;
  ov_word lex_fog;
  ov_word lex_isomesh_auto_state;
  ov_word lex_mesh_width;
  ov_word lex_cartoon_sampling;
  ov_word lex_cartoon_loop_radius;
  ov_word lex_cartoon_loop_quality;
  ov_word lex_cartoon_power;
  ov_word lex_cartoon_power_b;
  ov_word lex_cartoon_rect_length;
  ov_word lex_cartoon_rect_width;
  ov_word lex_internal_gui_width;
  ov_word lex_internal_gui;
  ov_word lex_cartoon_oval_length;
  ov_word lex_cartoon_oval_width;
  ov_word lex_cartoon_oval_quality;
  ov_word lex_cartoon_tube_radius;
  ov_word lex_cartoon_tube_quality;
  ov_word lex_cartoon_debug;
  ov_word lex_ribbon_width;
  ov_word lex_dash_width;
  ov_word lex_dash_radius;
  ov_word lex_cgo_ray_width_scale;
  ov_word lex_line_radius;
  ov_word lex_cartoon_round_helices;
  ov_word lex_cartoon_refine_normals;
  ov_word lex_cartoon_flat_sheets;
  ov_word lex_cartoon_smooth_loops;
  ov_word lex_cartoon_dumbbell_length;
  ov_word lex_cartoon_dumbbell_width;
  ov_word lex_cartoon_dumbbell_radius;
  ov_word lex_cartoon_fancy_helices;
  ov_word lex_cartoon_fancy_sheets;
  ov_word lex_ignore_pdb_segi;
  ov_word lex_ribbon_throw;
  ov_word lex_cartoon_throw;
  ov_word lex_cartoon_refine;
  ov_word lex_cartoon_refine_tips;
  ov_word lex_cartoon_discrete_colors;
  ov_word lex_normalize_ccp4_maps;
  ov_word lex_surface_poor;
  ov_word lex_internal_feedback;
  ov_word lex_cgo_line_width;
  ov_word lex_cgo_line_radius;
  ov_word lex_logging;
  ov_word lex_robust_logs;
  ov_word lex_log_box_selections;
  ov_word lex_log_conformations;
  ov_word lex_valence_size;
  ov_word lex_surface_miserable;
  ov_word lex_ray_opaque_background;
  ov_word lex_transparency;
  ov_word lex_ray_texture;
  ov_word lex_ray_texture_settings;
  ov_word lex_suspend_updates;
  ov_word lex_full_screen;
  ov_word lex_surface_mode;
  ov_word lex_surface_color;
  ov_word lex_mesh_mode;
  ov_word lex_mesh_color;
  ov_word lex_auto_indicate_flags;
  ov_word lex_surface_debug;
  ov_word lex_ray_improve_shadows;
  ov_word lex_smooth_color_triangle;
  ov_word lex_ray_default_renderer;
  ov_word lex_field_of_view;
  ov_word lex_reflect_power;
  ov_word lex_preserve_chempy_ids;
  ov_word lex_sphere_scale;
  ov_word lex_two_sided_lighting;
  ov_word lex_secondary_structure;
  ov_word lex_auto_remove_hydrogens;
  ov_word lex_raise_exceptions;
  ov_word lex_stop_on_exceptions;
  ov_word lex_sculpting;
  ov_word lex_auto_sculpt;
  ov_word lex_sculpt_vdw_scale;
  ov_word lex_sculpt_vdw_scale14;
  ov_word lex_sculpt_vdw_weight;
  ov_word lex_sculpt_vdw_weight14;
  ov_word lex_sculpt_bond_weight;
  ov_word lex_sculpt_angl_weight;
  ov_word lex_sculpt_pyra_weight;
  ov_word lex_sculpt_plan_weight;
  ov_word lex_sculpting_cycles;
  ov_word lex_sphere_transparency;
  ov_word lex_sphere_color;
  ov_word lex_sculpt_field_mask;
  ov_word lex_sculpt_hb_overlap;
  ov_word lex_sculpt_hb_overlap_base;
  ov_word lex_legacy_vdw_radii;
  ov_word lex_sculpt_memory;
  ov_word lex_connect_mode;
  ov_word lex_cartoon_cylindrical_helices;
  ov_word lex_cartoon_helix_radius;
  ov_word lex_connect_cutoff;
  ov_word lex_save_pdb_ss;
  ov_word lex_sculpt_line_weight;
  ov_word lex_fit_iterations;
  ov_word lex_fit_tolerance;
  ov_word lex_batch_prefix;
  ov_word lex_stereo_mode;
  ov_word lex_cgo_sphere_quality;
  ov_word lex_pdb_literal_names;
  ov_word lex_wrap_output;
  ov_word lex_fog_start;
  ov_word lex_state;
  ov_word lex_frame;
  ov_word lex_ray_shadows;
  ov_word lex_ribbon_trace_atoms;
  ov_word lex_security;
  ov_word lex_stick_transparency; 
  ov_word lex_ray_transparency_shadows;
  ov_word lex_session_version_check;
  ov_word lex_ray_transparency_specular;
  ov_word lex_stereo_double_pump_mono;
  ov_word lex_sphere_solvent;
  ov_word lex_mesh_quality;
  ov_word lex_mesh_solvent;
  ov_word lex_dot_solvent;
  ov_word lex_ray_shadow_fudge;
  ov_word lex_ray_triangle_fudge;
  ov_word lex_debug_pick;
  ov_word lex_dot_color;
  ov_word lex_mouse_limit;
  ov_word lex_mouse_scale;
  ov_word lex_transparency_mode;
  ov_word lex_clamp_colors;
  ov_word lex_pymol_space_max_red;
  ov_word lex_pymol_space_max_green;
  ov_word lex_pymol_space_max_blue;
  ov_word lex_pymol_space_min_factor;
  ov_word lex_roving_origin;
  ov_word lex_roving_lines;
  ov_word lex_roving_sticks;
  ov_word lex_roving_spheres;
  ov_word lex_roving_labels;
  ov_word lex_roving_delay;
  ov_word lex_roving_selection;
  ov_word lex_roving_byres;
  ov_word lex_roving_ribbon;
  ov_word lex_roving_cartoon;
  ov_word lex_roving_polar_contacts;
  ov_word lex_roving_polar_cutoff;
  ov_word lex_roving_nonbonded;
  ov_word lex_float_labels;
  ov_word lex_roving_detail;
  ov_word lex_roving_nb_spheres;
  ov_word lex_ribbon_color;
  ov_word lex_cartoon_color;
  ov_word lex_ribbon_smooth;
  ov_word lex_auto_color;
  ov_word lex_auto_color_next;
  ov_word lex_ray_interior_color;
  ov_word lex_cartoon_highlight_color;
  ov_word lex_coulomb_units_factor;
  ov_word lex_coulomb_dielectric;
  ov_word lex_ray_interior_shadows;
  ov_word lex_ray_interior_texture;

  ov_word lex_roving_map1_name;
  ov_word lex_roving_map2_name;
  ov_word lex_roving_map3_name;

  ov_word lex_roving_map1_level;
  ov_word lex_roving_map2_level;
  ov_word lex_roving_map3_level;

  ov_word lex_roving_isomesh;
  ov_word lex_roving_isosurface;
  ov_word lex_scenes_changed;

  ov_word lex_gaussian_b_adjust;
  ov_word lex_pdb_standard_order;

  ov_word lex_cartoon_smooth_first;
  ov_word lex_cartoon_smooth_last;
  ov_word lex_cartoon_smooth_cycles;
  ov_word lex_cartoon_flat_cycles;

  ov_word lex_max_threads;
  ov_word lex_show_progress;
  ov_word lex_use_display_lists;
  ov_word lex_cache_memory;
  ov_word lex_simplify_display_lists;
  ov_word lex_retain_order;
  ov_word lex_pdb_hetatm_sort;
  ov_word lex_pdb_use_ter_records;
  ov_word lex_cartoon_trace_atoms;
  ov_word lex_ray_oversample_cutoff;
  ov_word lex_gaussian_resolution;
  ov_word lex_gaussian_b_floor;
  ov_word lex_sculpt_nb_interval;
  ov_word lex_sculpt_tors_weight;
  ov_word lex_sculpt_tors_tolerance;
  ov_word lex_stick_ball;
  ov_word lex_stick_ball_ratio;
  ov_word lex_stick_fixed_radius;
  ov_word lex_cartoon_transparency;
  ov_word lex_dash_round_ends;
  ov_word lex_h_bond_max_angle;
  ov_word lex_h_bond_cutoff_center;
  ov_word lex_h_bond_cutoff_edge;
  ov_word lex_h_bond_power_a;
  ov_word lex_h_bond_power_b;
  ov_word lex_h_bond_cone;

  ov_word lex_ss_helix_psi_target; 
  ov_word lex_ss_helix_psi_include;
  ov_word lex_ss_helix_psi_exclude;

  ov_word lex_ss_helix_phi_target;
  ov_word lex_ss_helix_phi_include;
  ov_word lex_ss_helix_phi_exclude;

  ov_word lex_ss_strand_psi_target;
  ov_word lex_ss_strand_psi_include;
  ov_word lex_ss_strand_psi_exclude;

  ov_word lex_ss_strand_phi_target;
  ov_word lex_ss_strand_phi_include;
  ov_word lex_ss_strand_phi_exclude;
  ov_word lex_movie_loop;

  ov_word lex_pdb_retain_ids;
  ov_word lex_pdb_no_end_record;
  ov_word lex_cgo_dot_width;
  ov_word lex_cgo_dot_radius;
  ov_word lex_defer_updates;
  ov_word lex_normalize_o_maps;
  ov_word lex_swap_dsn6_bytes;
  ov_word lex_pdb_insertions_go_first;
  ov_word lex_roving_origin_z;
  ov_word lex_roving_origin_z_cushion;
  ov_word lex_specular_intensity;
  ov_word lex_overlay_lines;
  ov_word lex_ray_transparency_spec_cut;
  ov_word lex_internal_prompt;
  ov_word lex_normalize_grd_maps;
  ov_word lex_ray_blend_colors;
  ov_word lex_ray_blend_red;
  ov_word lex_ray_blend_green;
  ov_word lex_ray_blend_blue;
  ov_word lex_png_screen_gamma;
  ov_word lex_png_file_gamma;
  ov_word lex_editor_label_fragments;
  ov_word lex_internal_gui_control_size;
  ov_word lex_auto_dss;
  ov_word lex_transparency_picking_mode;
  ov_word lex_virtual_trackball;
  ov_word lex_pdb_reformat_names_mode;
  ov_word lex_ray_pixel_scale;
  ov_word lex_label_font_id;
  ov_word lex_pdb_conect_all;
  ov_word lex_button_mode_name;
  ov_word lex_surface_type;
  ov_word lex_dot_normals;
  ov_word lex_session_migration;
  ov_word lex_mesh_normals;
  ov_word lex_mesh_type;
  ov_word lex_dot_lighting;
  ov_word lex_mesh_lighting;
  ov_word lex_surface_solvent; 
  ov_word lex_triangle_max_passes;
  ov_word lex_ray_interior_reflect;
  ov_word lex_internal_gui_mode;
  ov_word lex_surface_carve_selection;
  ov_word lex_surface_carve_state;
  ov_word lex_surface_carve_cutoff;
  ov_word lex_surface_clear_selection;
  ov_word lex_surface_clear_state;
  ov_word lex_surface_clear_cutoff;
  ov_word lex_surface_trim_cutoff;
  ov_word lex_surface_trim_factor;
  ov_word lex_ray_max_passes;
  ov_word lex_active_selections;
  ov_word lex_ray_transparency_contrast;
  ov_word lex_seq_view;
  ov_word lex_mouse_selection_mode;
  ov_word lex_seq_view_label_spacing;
  ov_word lex_seq_view_label_start;
  ov_word lex_seq_view_format;
  ov_word lex_seq_view_location;
  ov_word lex_seq_view_overlay;
  ov_word lex_auto_classify_atoms;
  ov_word lex_cartoon_nucleic_acid_mode;
  ov_word lex_seq_view_color;
  ov_word lex_seq_view_label_mode;
  ov_word lex_surface_ramp_above_mode;
  ov_word lex_stereo;
  ov_word lex_wizard_prompt_mode;
  ov_word lex_coulomb_cutoff;
  ov_word lex_slice_track_camera;
  ov_word lex_slice_height_scale; 
  ov_word lex_slice_height_map;
  ov_word lex_slice_grid;
  ov_word lex_slice_dynamic_grid;
  ov_word lex_slice_dynamic_grid_resolution;
  ov_word lex_pdb_insure_orthogonal;
  ov_word lex_ray_direct_shade;
  ov_word lex_stick_color;
  ov_word lex_cartoon_putty_radius;
  ov_word lex_cartoon_putty_quality;
  ov_word lex_cartoon_putty_scale_min;
  ov_word lex_cartoon_putty_scale_max;
  ov_word lex_cartoon_putty_scale_power;
  ov_word lex_cartoon_putty_range;
  ov_word lex_cartoon_side_chain_helper;
  ov_word lex_surface_optimize_subsets;
  ov_word lex_multiplex;
  ov_word lex_texture_fonts;
  ov_word lex_pqr_workarounds;
  ov_word lex_animation;
  ov_word lex_animation_duration;
  ov_word lex_scene_animation;
  ov_word lex_line_stick_helper;
  ov_word lex_ray_orthoscopic;
  ov_word lex_ribbon_side_chain_helper;
  ov_word lex_selection_width_max;
  ov_word lex_selection_width_scale;
  ov_word lex_scene_current_name;
  ov_word lex_presentation;
  ov_word lex_presentation_mode;
  ov_word lex_pdb_truncate_residue_name;
  ov_word lex_scene_loop;
  ov_word lex_sweep_mode;
  ov_word lex_sweep_phase;
  ov_word lex_scene_restart_movie_delay;
  ov_word lex_mouse_restart_movie_delay;
  ov_word lex_angle_size;
  ov_word lex_angle_label_position;
  ov_word lex_dihedral_size;
  ov_word lex_dihedral_label_position;
  ov_word lex_defer_builds_mode;
  ov_word lex_seq_view_discrete_by_state;
  ov_word lex_scene_animation_duration;
  ov_word lex_wildcard;
  ov_word lex_atom_name_wildcard;
  ov_word lex_ignore_case;
  ov_word lex_presentation_auto_quit;
  ov_word lex_editor_auto_dihedral;
  ov_word lex_presentation_auto_start;
  ov_word lex_validate_object_names;
  /*  ov_word lex_ray_pixel_scale_limit;*/
  ov_word lex_auto_show_spheres;
  ov_word lex_sphere_mode;
  ov_word lex_sphere_point_max_size;
  ov_word lex_sphere_point_size;
  ov_word lex_pdb_honor_model_number;
  ov_word lex_rank_assisted_sorts;
  ov_word lex_ribbon_nucleic_acid_mode;
  ov_word lex_cartoon_ring_mode;
  ov_word lex_cartoon_ring_width;
  ov_word lex_cartoon_ring_color;
  ov_word lex_cartoon_ring_finder;
  ov_word lex_cartoon_tube_cap;
  ov_word lex_cartoon_loop_cap;
  ov_word lex_nvidia_bugs;
  ov_word lex_image_dots_per_inch;
  ov_word lex_opaque_background;
  ov_word lex_draw_frames;
  ov_word lex_show_alpha_checker;
  ov_word lex_matrix_mode;
  ov_word lex_editor_auto_origin;
  ov_word lex_session_file;
  ov_word lex_cgo_transparency;
  ov_word lex_legacy_mouse_zoom;
  ov_word lex_auto_number_selections;
  ov_word lex_sculpt_vdw_vis_mode;
  ov_word lex_sculpt_vdw_vis_min;
  ov_word lex_sculpt_vdw_vis_mid;
  ov_word lex_sculpt_vdw_vis_max;
  ov_word lex_cartoon_ladder_mode;
  ov_word lex_cartoon_ladder_radius;
  ov_word lex_cartoon_ladder_color;
  ov_word lex_cartoon_nucleic_acid_color;
  ov_word lex_cartoon_ring_transparency;
  ov_word lex_label_size;
  ov_word lex_spec_direct;
  ov_word lex_light_count;
  ov_word lex_light2;
  ov_word lex_light3;
  ov_word lex_hide_underscore_names;
  ov_word lex_selection_round_points;
  ov_word lex_distance_exclusion;
  ov_word lex_h_bond_exclusion;
  ov_word lex_label_shadow_mode;
  ov_word lex_light4;
  ov_word lex_light5;
  ov_word lex_light6;
  ov_word lex_light7;
  ov_word lex_label_outline_color;
  ov_word lex_ray_trace_mode;
  ov_word lex_ray_trace_gain;
  ov_word lex_selection_visible_only;
  ov_word lex_label_position;
  ov_word lex_ray_trace_depth_factor;
  ov_word lex_ray_trace_slope_factor;
  ov_word lex_ray_trace_disco_factor;
  ov_word lex_ray_shadow_decay_factor;
  ov_word lex_ray_interior_mode;
  ov_word lex_ray_legacy_lighting;
  ov_word lex_sculpt_auto_center;
  ov_word lex_pdb_discrete_chains;
  ov_word lex_pdb_unbond_cations; 
  ov_word lex_sculpt_tri_scale;
  ov_word lex_sculpt_tri_weight;
  ov_word lex_sculpt_tri_min;
  ov_word lex_sculpt_tri_max;
  ov_word lex_sculpt_tri_mode;
  ov_word lex_pdb_echo_tags;
  ov_word lex_connect_bonded;
  ov_word lex_spec_direct_power;
  ov_word lex_light8;
  ov_word lex_light9;
  ov_word lex_ray_shadow_decay_range;
  ov_word lex_spec_count;
  ov_word lex_sculpt_min_scale;
  ov_word lex_sculpt_min_weight;
  ov_word lex_sculpt_min_min;
  ov_word lex_sculpt_min_max;
  ov_word lex_sculpt_max_scale;
  ov_word lex_sculpt_max_weight;
  ov_word lex_sculpt_max_min;
  ov_word lex_sculpt_max_max;
  ov_word lex_surface_circumscribe;
  ov_word lex_sculpt_avd_weight;          
  ov_word lex_sculpt_avd_gap;  
  ov_word lex_sculpt_avd_range;
  ov_word lex_sculpt_avd_excl;
  ov_word lex_async_builds;
  ov_word lex_fetch_path;
  ov_word lex_cartoon_ring_radius;
  ov_word lex_ray_color_ramps;
  ov_word lex_ray_hint_camera;
  ov_word lex_ray_hint_shadow;
  ov_word lex_stick_valence_scale;
} _CPyMOL;

/* convenience functions -- inline */

#ifdef _PYMOL_INLINE
#define CC_INLINE __inline__
#else
#define CC_INLINE
#endif

CC_INLINE static PyMOLstatus get_status_ok(int ok) 
{
  if(ok) 
    return PyMOLstatus_SUCCESS;
  else
    return PyMOLstatus_FAILURE;
}

CC_INLINE static PyMOLreturn_status return_status_ok(int ok)
{
  PyMOLreturn_status result;
  result.status = get_status_ok(ok);
  return result;
}

CC_INLINE static PyMOLreturn_status return_status(int status)
{
  PyMOLreturn_status result;
  result.status = status;
  return result;
}

static OVstatus PyMOL_InitAPI(CPyMOL *I)
{
  OVContext *C = I->G->Context;
  OVreturn_word result;
  I->Lex = OVLexicon_New(C->heap);
  if(!I->Lex) 
    return_OVstatus_FAILURE;

  /* the following preprocessor macros may require GNU's cpp or VC++
     we'll see... */

#define LEX(ARG)  \
  if(!OVreturn_IS_OK( (result= OVLexicon_GetFromCString(I->Lex,#ARG))))  \
    return_OVstatus_FAILURE \
    else \
      I -> lex_ ## ARG = result.word;
  
  LEX(pdb);
  LEX(sdf);
  LEX(mol);
  LEX(mol2);
  LEX(xplor);
  LEX(ccp4);

  LEX(string);
  LEX(filename);
  LEX(raw);

  /* string constants that are accepted on input */

#define LEX_REP(NAME,CODE) LEX(NAME) \
    if(!OVreturn_IS_OK( OVOneToOne_Set(I->Rep,I->lex_ ## NAME, CODE)))  \
      return_OVstatus_FAILURE;

  I->Rep = OVOneToOne_New(C->heap);
  if(!I->Rep)
    return_OVstatus_FAILURE;
  
  LEX_REP(everything,-1);
  LEX_REP(sticks,0);
  LEX_REP(spheres,1);
  LEX_REP(surface,2);
  LEX_REP(labels,3);
  LEX_REP(nb_spheres,4);
  LEX_REP(cartoon,5);
  LEX_REP(ribbon,6);
  LEX_REP(lines,7);
  LEX_REP(mesh,8);
  LEX_REP(dots,9);
  LEX_REP(dashes,10);
  LEX_REP(nonbonded,11);
  LEX_REP(cell,12);
  LEX_REP(cgo,13);
  LEX_REP(callback,14);
  LEX_REP(extent,15);
  LEX_REP(slice,16);

  /* workaround for unexplained bug with nested macro on VC6 */

#define LEX_CLIP(NAME,CODE) {if(!OVreturn_IS_OK( (result= OVLexicon_GetFromCString(I->Lex,#NAME))))  \
    return_OVstatus_FAILURE \
    else \
    I -> lex_ ## NAME = result.word;} \
    if(!OVreturn_IS_OK( OVOneToOne_Set(I->Clip,I->lex_ ## NAME, CODE)))  \
      return_OVstatus_FAILURE;
  
  I->Clip = OVOneToOne_New(C->heap);
  if(!I->Clip)
    return_OVstatus_FAILURE;

  LEX_CLIP(near,0);
  LEX_CLIP(far,1);
  LEX_CLIP(move,2);
  LEX_CLIP(slab,3);
  LEX_CLIP(atoms,4);

#define LEX_SELLIST(NAME,CODE) {if(!OVreturn_IS_OK( (result= OVLexicon_GetFromCString(I->Lex,#NAME))))  \
    return_OVstatus_FAILURE \
    else \
    I -> lex_ ## NAME = result.word;} \
    if(!OVreturn_IS_OK( OVOneToOne_Set(I->SelectList,I->lex_ ## NAME, CODE)))  \
      return_OVstatus_FAILURE;
  
  I->SelectList = OVOneToOne_New(C->heap);
  if(!I->SelectList)
    return_OVstatus_FAILURE;

  LEX_SELLIST(index,0);
  LEX_SELLIST(id,1);
  LEX_SELLIST(rank,2);

  I->Setting = OVOneToOne_New(C->heap);
  if(!I->Setting)
    return_OVstatus_FAILURE;

#define LEX_SETTING(NAME,CODE) LEX(NAME) \
    if(!OVreturn_IS_OK( OVOneToOne_Set(I->Setting,I->lex_ ## NAME, CODE)))  \
      return_OVstatus_FAILURE;

  LEX_SETTING(bonding_vdw_cutoff, 0);
  LEX_SETTING(min_mesh_spacing, 1);
  LEX_SETTING(dot_density, 2);
  LEX_SETTING(dot_mode, 3);
  LEX_SETTING(solvent_radius, 4);
  LEX_SETTING(sel_counter, 5);
  LEX_SETTING(bg_rgb, 6);
  LEX_SETTING(ambient, 7);
  LEX_SETTING(direct, 8);
  LEX_SETTING(reflect, 9);
  LEX_SETTING(light, 10);
  LEX_SETTING(power, 11);
  LEX_SETTING(antialias, 12);
  LEX_SETTING(cavity_cull, 13);
  LEX_SETTING(gl_ambient, 14);
  LEX_SETTING(single_image, 15);
  LEX_SETTING(movie_delay, 16);
  LEX_SETTING(ribbon_power, 17);
  LEX_SETTING(ribbon_power_b, 18);
  LEX_SETTING(ribbon_sampling, 19);
  LEX_SETTING(ribbon_radius, 20);
  LEX_SETTING(stick_radius, 21);
  LEX_SETTING(hash_max, 22);
  LEX_SETTING(ortho, 23);
  LEX_SETTING(spec_reflect, 24);
  LEX_SETTING(spec_power, 25);
  LEX_SETTING(sweep_angle, 26);
  LEX_SETTING(sweep_speed, 27);
  LEX_SETTING(dot_hydrogens, 28);
  LEX_SETTING(dot_radius, 29);
  LEX_SETTING(ray_trace_frames, 30);
  LEX_SETTING(cache_frames, 31);
  LEX_SETTING(trim_dots, 32);
  LEX_SETTING(cull_spheres, 33);
  LEX_SETTING(test1, 34);
  LEX_SETTING(test2, 35);
  LEX_SETTING(surface_best, 36);
  LEX_SETTING(surface_normal, 37);
  LEX_SETTING(surface_quality, 38);
  LEX_SETTING(surface_proximity, 39);
  LEX_SETTING(normal_workaround, 40);
  LEX_SETTING(stereo_angle, 41);
  LEX_SETTING(stereo_shift, 42);
  LEX_SETTING(line_smooth, 43);
  LEX_SETTING(line_width, 44);
  LEX_SETTING(half_bonds, 45);
  LEX_SETTING(stick_quality, 46);
  LEX_SETTING(stick_overlap, 47);
  LEX_SETTING(stick_nub, 48);
  LEX_SETTING(all_states, 49);
  LEX_SETTING(pickable, 50);
  LEX_SETTING(auto_show_lines, 51);
  LEX_SETTING(idle_delay, 52);
  LEX_SETTING(no_idle, 53);
  LEX_SETTING(fast_idle, 54);
  LEX_SETTING(slow_idle, 55);
  LEX_SETTING(rock_delay, 56);
  LEX_SETTING(dist_counter, 57);
  LEX_SETTING(dash_length, 58);
  LEX_SETTING(dash_gap, 59);
  LEX_SETTING(auto_zoom, 60);
  LEX_SETTING(overlay, 61);
  LEX_SETTING(text, 62);
  LEX_SETTING(button_mode, 63);
  LEX_SETTING(valence, 64);
  LEX_SETTING(nonbonded_size, 65);
  LEX_SETTING(label_color, 66);
  LEX_SETTING(ray_trace_fog, 67);
  LEX_SETTING(spheroid_scale, 68);
  LEX_SETTING(ray_trace_fog_start, 69);
  LEX_SETTING(spheroid_smooth, 70);
  LEX_SETTING(spheroid_fill, 71);
  LEX_SETTING(auto_show_nonbonded, 72);
  LEX_SETTING(cache_display, 73);
  LEX_SETTING(mesh_radius, 74);
  LEX_SETTING(backface_cull, 75);
  LEX_SETTING(gamma, 76);
  LEX_SETTING(dot_width, 77);
  LEX_SETTING(auto_show_selections, 78);
  LEX_SETTING(auto_hide_selections, 79);
  LEX_SETTING(selection_width, 80);
  LEX_SETTING(selection_overlay, 81);
  LEX_SETTING(static_singletons, 82);
  LEX_SETTING(max_triangles, 83);
  LEX_SETTING(depth_cue, 84);
  LEX_SETTING(specular, 85);
  LEX_SETTING(shininess, 86);
  LEX_SETTING(sphere_quality, 87);
  LEX_SETTING(fog, 88);
  LEX_SETTING(isomesh_auto_state, 89);
  LEX_SETTING(mesh_width, 90);
  LEX_SETTING(cartoon_sampling, 91);
  LEX_SETTING(cartoon_loop_radius, 92);
  LEX_SETTING(cartoon_loop_quality, 93);
  LEX_SETTING(cartoon_power, 94);
  LEX_SETTING(cartoon_power_b, 95);
  LEX_SETTING(cartoon_rect_length, 96);
  LEX_SETTING(cartoon_rect_width, 97);
  LEX_SETTING(internal_gui_width, 98);
  LEX_SETTING(internal_gui, 99);
  LEX_SETTING(cartoon_oval_length, 100);
  LEX_SETTING(cartoon_oval_width, 101);
  LEX_SETTING(cartoon_oval_quality, 102);
  LEX_SETTING(cartoon_tube_radius, 103);
  LEX_SETTING(cartoon_tube_quality, 104);
  LEX_SETTING(cartoon_debug, 105);
  LEX_SETTING(ribbon_width, 106);
  LEX_SETTING(dash_width, 107);
  LEX_SETTING(dash_radius, 108);
  LEX_SETTING(cgo_ray_width_scale, 109);
  LEX_SETTING(line_radius, 110);
  LEX_SETTING(cartoon_round_helices, 111);
  LEX_SETTING(cartoon_refine_normals, 112);
  LEX_SETTING(cartoon_flat_sheets, 113);
  LEX_SETTING(cartoon_smooth_loops, 114);
  LEX_SETTING(cartoon_dumbbell_length, 115);
  LEX_SETTING(cartoon_dumbbell_width, 116);
  LEX_SETTING(cartoon_dumbbell_radius, 117);
  LEX_SETTING(cartoon_fancy_helices, 118);
  LEX_SETTING(cartoon_fancy_sheets, 119);
  LEX_SETTING(ignore_pdb_segi, 120);
  LEX_SETTING(ribbon_throw, 121);
  LEX_SETTING(cartoon_throw, 122);
  LEX_SETTING(cartoon_refine, 123);
  LEX_SETTING(cartoon_refine_tips, 124);
  LEX_SETTING(cartoon_discrete_colors, 125);
  LEX_SETTING(normalize_ccp4_maps, 126);
  LEX_SETTING(surface_poor, 127);
  LEX_SETTING(internal_feedback, 128);
  LEX_SETTING(cgo_line_width, 129);
  LEX_SETTING(cgo_line_radius, 130);
  LEX_SETTING(logging, 131);
  LEX_SETTING(robust_logs, 132);
  LEX_SETTING(log_box_selections, 133);
  LEX_SETTING(log_conformations, 134);
  LEX_SETTING(valence_size, 135);
  LEX_SETTING(surface_miserable, 136);
  LEX_SETTING(ray_opaque_background, 137);
  LEX_SETTING(transparency, 138);
  LEX_SETTING(ray_texture, 139);
  LEX_SETTING(ray_texture_settings, 140);
  LEX_SETTING(suspend_updates, 141);
  LEX_SETTING(full_screen, 142);
  LEX_SETTING(surface_mode, 143);
  LEX_SETTING(surface_color, 144);
  LEX_SETTING(mesh_mode, 145);
  LEX_SETTING(mesh_color, 146);
  LEX_SETTING(auto_indicate_flags, 147);
  LEX_SETTING(surface_debug, 148);
  LEX_SETTING(ray_improve_shadows, 149);
  LEX_SETTING(smooth_color_triangle, 150);
  LEX_SETTING(ray_default_renderer, 151);
  LEX_SETTING(field_of_view, 152);
  LEX_SETTING(reflect_power, 153);
  LEX_SETTING(preserve_chempy_ids, 154);
  LEX_SETTING(sphere_scale, 155);
  LEX_SETTING(two_sided_lighting, 156);
  LEX_SETTING(secondary_structure, 157);
  LEX_SETTING(auto_remove_hydrogens, 158);
  LEX_SETTING(raise_exceptions, 159);
  LEX_SETTING(stop_on_exceptions, 160);
  LEX_SETTING(sculpting, 161);
  LEX_SETTING(auto_sculpt, 162);
  LEX_SETTING(sculpt_vdw_scale, 163);
  LEX_SETTING(sculpt_vdw_scale14, 164);
  LEX_SETTING(sculpt_vdw_weight, 165);
  LEX_SETTING(sculpt_vdw_weight14, 166);
  LEX_SETTING(sculpt_bond_weight, 167);
  LEX_SETTING(sculpt_angl_weight, 168);
  LEX_SETTING(sculpt_pyra_weight, 169);
  LEX_SETTING(sculpt_plan_weight, 170);
  LEX_SETTING(sculpting_cycles, 171);
  LEX_SETTING(sphere_transparency, 172);
  LEX_SETTING(sphere_color, 173);
  LEX_SETTING(sculpt_field_mask, 174);
  LEX_SETTING(sculpt_hb_overlap, 175);
  LEX_SETTING(sculpt_hb_overlap_base, 176);
  LEX_SETTING(legacy_vdw_radii, 177);
  LEX_SETTING(sculpt_memory, 178);
  LEX_SETTING(connect_mode, 179);
  LEX_SETTING(cartoon_cylindrical_helices, 180);
  LEX_SETTING(cartoon_helix_radius, 181);
  LEX_SETTING(connect_cutoff, 182);
  LEX_SETTING(save_pdb_ss, 183);
  LEX_SETTING(sculpt_line_weight, 184);
  LEX_SETTING(fit_iterations, 185);
  LEX_SETTING(fit_tolerance, 186);
  LEX_SETTING(batch_prefix, 187);
  LEX_SETTING(stereo_mode, 188);
  LEX_SETTING(cgo_sphere_quality, 189);
  LEX_SETTING(pdb_literal_names, 190);
  LEX_SETTING(wrap_output, 191);
  LEX_SETTING(fog_start, 192);
  LEX_SETTING(state, 193);
  LEX_SETTING(frame, 194);
  LEX_SETTING(ray_shadows, 195);
  LEX_SETTING(ribbon_trace_atoms, 196);
  LEX_SETTING(security, 197);
  LEX_SETTING(stick_transparency, 198); 
  LEX_SETTING(ray_transparency_shadows, 199);
  LEX_SETTING(session_version_check, 200);
  LEX_SETTING(ray_transparency_specular, 201);
  LEX_SETTING(stereo_double_pump_mono, 202);
  LEX_SETTING(sphere_solvent, 203);
  LEX_SETTING(mesh_quality, 204);
  LEX_SETTING(mesh_solvent, 205);
  LEX_SETTING(dot_solvent, 206);
  LEX_SETTING(ray_shadow_fudge, 207);
  LEX_SETTING(ray_triangle_fudge, 208);
  LEX_SETTING(debug_pick, 209);
  LEX_SETTING(dot_color, 210);
  LEX_SETTING(mouse_limit, 211);
  LEX_SETTING(mouse_scale, 212);
  LEX_SETTING(transparency_mode, 213);
  LEX_SETTING(clamp_colors, 214);
  LEX_SETTING(pymol_space_max_red, 215);
  LEX_SETTING(pymol_space_max_green, 216);
  LEX_SETTING(pymol_space_max_blue, 217);
  LEX_SETTING(pymol_space_min_factor, 218);
  LEX_SETTING(roving_origin, 219);
  LEX_SETTING(roving_lines, 220);
  LEX_SETTING(roving_sticks, 221);
  LEX_SETTING(roving_spheres, 222);
  LEX_SETTING(roving_labels, 223);
  LEX_SETTING(roving_delay, 224);
  LEX_SETTING(roving_selection, 225);
  LEX_SETTING(roving_byres, 226);
  LEX_SETTING(roving_ribbon, 227);
  LEX_SETTING(roving_cartoon, 228);
  LEX_SETTING(roving_polar_contacts, 229);
  LEX_SETTING(roving_polar_cutoff, 230);
  LEX_SETTING(roving_nonbonded, 231);
  LEX_SETTING(float_labels, 232);
  LEX_SETTING(roving_detail, 233);
  LEX_SETTING(roving_nb_spheres, 234);
  LEX_SETTING(ribbon_color, 235);
  LEX_SETTING(cartoon_color, 236);
  LEX_SETTING(ribbon_smooth, 237);
  LEX_SETTING(auto_color, 238);
  LEX_SETTING(auto_color_next, 239);
  LEX_SETTING(ray_interior_color, 240);
  LEX_SETTING(cartoon_highlight_color, 241);
  LEX_SETTING(coulomb_units_factor, 242);
  LEX_SETTING(coulomb_dielectric, 243);
  LEX_SETTING(ray_interior_shadows, 244);
  LEX_SETTING(ray_interior_texture, 245);

  LEX_SETTING(roving_map1_name, 246);
  LEX_SETTING(roving_map2_name, 247);
  LEX_SETTING(roving_map3_name, 248);

  LEX_SETTING(roving_map1_level, 249);
  LEX_SETTING(roving_map2_level, 250);
  LEX_SETTING(roving_map3_level, 251);

  LEX_SETTING(roving_isomesh, 252);
  LEX_SETTING(roving_isosurface, 253);
  LEX_SETTING(scenes_changed, 254);

  LEX_SETTING(gaussian_b_adjust, 255);
  LEX_SETTING(pdb_standard_order, 256);

  LEX_SETTING(cartoon_smooth_first, 257);
  LEX_SETTING(cartoon_smooth_last, 258);
  LEX_SETTING(cartoon_smooth_cycles, 259);
  LEX_SETTING(cartoon_flat_cycles, 260);

  LEX_SETTING(max_threads, 261);
  LEX_SETTING(show_progress, 262);
  LEX_SETTING(use_display_lists, 263);
  LEX_SETTING(cache_memory, 264);
  LEX_SETTING(simplify_display_lists, 265);
  LEX_SETTING(retain_order, 266);
  LEX_SETTING(pdb_hetatm_sort, 267);
  LEX_SETTING(pdb_use_ter_records, 268);
  LEX_SETTING(cartoon_trace_atoms, 269);
  LEX_SETTING(ray_oversample_cutoff, 270);
  LEX_SETTING(gaussian_resolution, 271);
  LEX_SETTING(gaussian_b_floor, 272);
  LEX_SETTING(sculpt_nb_interval, 273);
  LEX_SETTING(sculpt_tors_weight, 274);
  LEX_SETTING(sculpt_tors_tolerance, 275);
  LEX_SETTING(stick_ball, 276);
  LEX_SETTING(stick_ball_ratio, 277);
  LEX_SETTING(stick_fixed_radius, 278);
  LEX_SETTING(cartoon_transparency, 279);
  LEX_SETTING(dash_round_ends, 280);
  LEX_SETTING(h_bond_max_angle, 281);
  LEX_SETTING(h_bond_cutoff_center, 282);
  LEX_SETTING(h_bond_cutoff_edge, 283);
  LEX_SETTING(h_bond_power_a, 284);
  LEX_SETTING(h_bond_power_b, 285);
  LEX_SETTING(h_bond_cone, 286);

  LEX_SETTING(ss_helix_psi_target, 287); 
  LEX_SETTING(ss_helix_psi_include, 288);
  LEX_SETTING(ss_helix_psi_exclude, 289);

  LEX_SETTING(ss_helix_phi_target, 290);
  LEX_SETTING(ss_helix_phi_include, 291);
  LEX_SETTING(ss_helix_phi_exclude, 292);

  LEX_SETTING(ss_strand_psi_target, 293);
  LEX_SETTING(ss_strand_psi_include, 294);
  LEX_SETTING(ss_strand_psi_exclude, 295);

  LEX_SETTING(ss_strand_phi_target, 296);
  LEX_SETTING(ss_strand_phi_include, 297);
  LEX_SETTING(ss_strand_phi_exclude, 298);
  LEX_SETTING(movie_loop, 299);

  LEX_SETTING(pdb_retain_ids, 300);
  LEX_SETTING(pdb_no_end_record, 301);
  LEX_SETTING(cgo_dot_width, 302);
  LEX_SETTING(cgo_dot_radius, 303);
  LEX_SETTING(defer_updates, 304);
  LEX_SETTING(normalize_o_maps, 305);
  LEX_SETTING(swap_dsn6_bytes, 306);
  LEX_SETTING(pdb_insertions_go_first, 307);
  LEX_SETTING(roving_origin_z, 308);
  LEX_SETTING(roving_origin_z_cushion, 309);
  LEX_SETTING(specular_intensity, 310);
  LEX_SETTING(overlay_lines, 311);
  LEX_SETTING(ray_transparency_spec_cut, 312);
  LEX_SETTING(internal_prompt, 313);
  LEX_SETTING(normalize_grd_maps, 314);
  LEX_SETTING(ray_blend_colors, 315);
  LEX_SETTING(ray_blend_red, 316);
  LEX_SETTING(ray_blend_green, 317);
  LEX_SETTING(ray_blend_blue, 318);
  LEX_SETTING(png_screen_gamma, 319);
  LEX_SETTING(png_file_gamma, 320);
  LEX_SETTING(editor_label_fragments, 321);
  LEX_SETTING(internal_gui_control_size, 322);
  LEX_SETTING(auto_dss, 323);
  LEX_SETTING(transparency_picking_mode, 324);
  LEX_SETTING(virtual_trackball, 325);
  LEX_SETTING(pdb_reformat_names_mode, 326);
  LEX_SETTING(ray_pixel_scale, 327);
  LEX_SETTING(label_font_id, 328);
  LEX_SETTING(pdb_conect_all, 329);
  LEX_SETTING(button_mode_name, 330);
  LEX_SETTING(surface_type, 331);
  LEX_SETTING(dot_normals, 332);
  LEX_SETTING(session_migration, 333);
  LEX_SETTING(mesh_normals, 334);
  LEX_SETTING(mesh_type, 335);
  LEX_SETTING(dot_lighting, 336);
  LEX_SETTING(mesh_lighting, 337);
  LEX_SETTING(surface_solvent, 338); 
  LEX_SETTING(triangle_max_passes, 339);
  LEX_SETTING(ray_interior_reflect, 340);
  LEX_SETTING(internal_gui_mode, 341);
  LEX_SETTING(surface_carve_selection, 342);
  LEX_SETTING(surface_carve_state, 343);
  LEX_SETTING(surface_carve_cutoff, 344);
  LEX_SETTING(surface_clear_selection, 345);
  LEX_SETTING(surface_clear_state, 346);
  LEX_SETTING(surface_clear_cutoff, 347);
  LEX_SETTING(surface_trim_cutoff, 348);
  LEX_SETTING(surface_trim_factor, 349);
  LEX_SETTING(ray_max_passes, 350);
  LEX_SETTING(active_selections, 351);
  LEX_SETTING(ray_transparency_contrast, 352);
  LEX_SETTING(seq_view, 353);
  LEX_SETTING(mouse_selection_mode, 354);
  LEX_SETTING(seq_view_label_spacing, 355);
  LEX_SETTING(seq_view_label_start, 356);
  LEX_SETTING(seq_view_format, 357);
  LEX_SETTING(seq_view_location, 358);
  LEX_SETTING(seq_view_overlay, 359);
  LEX_SETTING(auto_classify_atoms, 360);
  LEX_SETTING(cartoon_nucleic_acid_mode, 361);
  LEX_SETTING(seq_view_color, 362);
  LEX_SETTING(seq_view_label_mode, 363);
  LEX_SETTING(surface_ramp_above_mode, 364);
  LEX_SETTING(stereo, 365);
  LEX_SETTING(wizard_prompt_mode, 366);
  LEX_SETTING(coulomb_cutoff, 367);
  LEX_SETTING(slice_track_camera, 368);
  LEX_SETTING(slice_height_scale, 369); 
  LEX_SETTING(slice_height_map, 370);
  LEX_SETTING(slice_grid, 371);
  LEX_SETTING(slice_dynamic_grid, 372);
  LEX_SETTING(slice_dynamic_grid_resolution, 373);
  LEX_SETTING(pdb_insure_orthogonal, 374);
  LEX_SETTING(ray_direct_shade, 375);
  LEX_SETTING(stick_color, 376);
  LEX_SETTING(cartoon_putty_radius, 377);
  LEX_SETTING(cartoon_putty_quality, 378);
  LEX_SETTING(cartoon_putty_scale_min, 379);
  LEX_SETTING(cartoon_putty_scale_max, 380);
  LEX_SETTING(cartoon_putty_scale_power, 381);
  LEX_SETTING(cartoon_putty_range, 382);
  LEX_SETTING(cartoon_side_chain_helper, 383);
  LEX_SETTING(surface_optimize_subsets, 384);
  LEX_SETTING(multiplex, 385);
  LEX_SETTING(texture_fonts, 386);
  LEX_SETTING(pqr_workarounds, 387);
  LEX_SETTING(animation, 388);
  LEX_SETTING(animation_duration, 389);
  LEX_SETTING(scene_animation, 390);
  LEX_SETTING(line_stick_helper, 391);
  LEX_SETTING(ray_orthoscopic, 392);
  LEX_SETTING(ribbon_side_chain_helper, 393);
  LEX_SETTING(selection_width_max, 394);
  LEX_SETTING(selection_width_scale, 395);
  LEX_SETTING(scene_current_name, 396);
  LEX_SETTING(presentation, 397);
  LEX_SETTING(presentation_mode, 398);
  LEX_SETTING(pdb_truncate_residue_name, 399);
  LEX_SETTING(scene_loop, 400);
  LEX_SETTING(sweep_mode, 401);
  LEX_SETTING(sweep_phase, 402);
  LEX_SETTING(scene_restart_movie_delay, 403);
  LEX_SETTING(mouse_restart_movie_delay, 404);
  LEX_SETTING(angle_size, 405);
  LEX_SETTING(angle_label_position, 406);
  LEX_SETTING(dihedral_size, 407);
  LEX_SETTING(dihedral_label_position, 408);
  LEX_SETTING(defer_builds_mode, 409);
  LEX_SETTING(seq_view_discrete_by_state, 410);
  LEX_SETTING(scene_animation_duration, 411);
  LEX_SETTING(wildcard,412);
  LEX_SETTING(atom_name_wildcard,413);
  LEX_SETTING(ignore_case,414);
  LEX_SETTING(presentation_auto_quit,415);
  LEX_SETTING(editor_auto_dihedral,416);
  LEX_SETTING(presentation_auto_start,417);
  LEX_SETTING(validate_object_names,418);
  /*  LEX_SETTING(ray_pixel_scale_limit, 419);*/
  LEX_SETTING(auto_show_spheres, 420);
  LEX_SETTING(sphere_mode, 421);
  LEX_SETTING(sphere_point_max_size, 422);
  LEX_SETTING(sphere_point_size, 423);
  LEX_SETTING(pdb_honor_model_number, 424);
  LEX_SETTING(rank_assisted_sorts, 425);
  LEX_SETTING(ribbon_nucleic_acid_mode, 426);
  LEX_SETTING(cartoon_ring_mode, 427);
  LEX_SETTING(cartoon_ring_width, 428);
  LEX_SETTING(cartoon_ring_color, 429);
  LEX_SETTING(cartoon_ring_finder, 430);
  LEX_SETTING(cartoon_tube_cap, 431);
  LEX_SETTING(cartoon_loop_cap, 432);
  LEX_SETTING(nvidia_bugs, 433);
  LEX_SETTING(image_dots_per_inch, 434);
  LEX_SETTING(opaque_background, 435);
  LEX_SETTING(draw_frames, 436);
  LEX_SETTING(show_alpha_checker, 437);
  LEX_SETTING(matrix_mode, 438);
  LEX_SETTING(editor_auto_origin, 439);
  LEX_SETTING(session_file, 440);
  LEX_SETTING(cgo_transparency, 441);
  LEX_SETTING(legacy_mouse_zoom, 442);
  LEX_SETTING(auto_number_selections, 443);
  LEX_SETTING(sculpt_vdw_vis_mode, 444);
  LEX_SETTING(sculpt_vdw_vis_min, 445);
  LEX_SETTING(sculpt_vdw_vis_mid, 446);
  LEX_SETTING(sculpt_vdw_vis_max, 447);
  LEX_SETTING(cartoon_ladder_mode, 448);
  LEX_SETTING(cartoon_ladder_radius, 449);
  LEX_SETTING(cartoon_ladder_color, 450);
  LEX_SETTING(cartoon_nucleic_acid_color, 451);
  LEX_SETTING(cartoon_ring_transparency, 452);
  LEX_SETTING(label_size, 453);
  LEX_SETTING(spec_direct, 454);
  LEX_SETTING(light_count, 455);
  LEX_SETTING(light2, 456);
  LEX_SETTING(light3, 457);
  LEX_SETTING(hide_underscore_names, 458);
  LEX_SETTING(selection_round_points, 459);
  LEX_SETTING(distance_exclusion, 460);
  LEX_SETTING(h_bond_exclusion, 461);
  LEX_SETTING(label_shadow_mode, 462);
  LEX_SETTING(light4, 463);
  LEX_SETTING(light5, 464);
  LEX_SETTING(light6, 465);
  LEX_SETTING(light7, 466);
  LEX_SETTING(label_outline_color, 467);
  LEX_SETTING(ray_trace_mode,468);
  LEX_SETTING(ray_trace_gain,469);
  LEX_SETTING(selection_visible_only,470);
  LEX_SETTING(label_position,471);
  LEX_SETTING(ray_trace_depth_factor,472);
  LEX_SETTING(ray_trace_slope_factor,473);
  LEX_SETTING(ray_trace_disco_factor,474);
  LEX_SETTING(ray_shadow_decay_factor, 475);
  LEX_SETTING(ray_interior_mode, 476);
  LEX_SETTING(ray_legacy_lighting, 477);
  LEX_SETTING(sculpt_auto_center, 478);
  LEX_SETTING(pdb_discrete_chains, 479);
  LEX_SETTING(pdb_unbond_cations, 480);
  LEX_SETTING(sculpt_tri_scale, 481);
  LEX_SETTING(sculpt_tri_weight, 482);
  LEX_SETTING(sculpt_tri_min, 483);
  LEX_SETTING(sculpt_tri_max, 484);
  LEX_SETTING(sculpt_tri_mode, 485);
  LEX_SETTING(pdb_echo_tags, 486);
  LEX_SETTING(connect_bonded, 487);
  LEX_SETTING(spec_direct_power, 488);
  LEX_SETTING(light8, 489);
  LEX_SETTING(light9, 490);
  LEX_SETTING(ray_shadow_decay_range, 491);
  LEX_SETTING(spec_count, 492);
  LEX_SETTING(sculpt_min_scale, 493);
  LEX_SETTING(sculpt_min_weight, 494);
  LEX_SETTING(sculpt_min_min, 495);
  LEX_SETTING(sculpt_min_max, 496);
  LEX_SETTING(sculpt_max_scale, 497);
  LEX_SETTING(sculpt_max_weight, 498);
  LEX_SETTING(sculpt_max_min, 499);
  LEX_SETTING(sculpt_max_max, 500);
  LEX_SETTING(surface_circumscribe, 501);
  LEX_SETTING(sculpt_avd_weight, 502);
  LEX_SETTING(sculpt_avd_gap, 503);
  LEX_SETTING(sculpt_avd_range, 504);
  LEX_SETTING(sculpt_avd_excl, 505);
  LEX_SETTING(async_builds, 506);
  LEX_SETTING(fetch_path, 507);
  LEX_SETTING(cartoon_ring_radius, 508);
  LEX_SETTING(ray_color_ramps,509);
  LEX_SETTING(ray_hint_camera,510);
  LEX_SETTING(ray_hint_shadow,511);
  LEX_SETTING(stick_valence_scale,512);

  return_OVstatus_SUCCESS;
}

int PyMOL_NewG3DStream(CPyMOL *I,int **array_ptr)
{
  int *return_vla = ExecutiveGetG3d(I->G);
  int result = OVstatus_FAILURE;
  if(return_vla) {
    result = VLAGetSize(return_vla)*(sizeof(G3dPrimitive)/sizeof(int));
  }
  if(array_ptr)
    *array_ptr = return_vla;
  return result;
}

int PyMOL_DelG3DStream(CPyMOL *I,int *array_ptr)
{
  VLAFreeP(array_ptr);
  return OVstatus_SUCCESS;
}


static OVstatus PyMOL_PurgeAPI(CPyMOL *I)
{
  OVOneToOne_DEL_AUTO_NULL(I->Setting);
  OVOneToOne_DEL_AUTO_NULL(I->Clip);
  OVOneToOne_DEL_AUTO_NULL(I->SelectList);
  OVOneToOne_DEL_AUTO_NULL(I->Rep);
  OVLexicon_DEL_AUTO_NULL(I->Lex);
  return_OVstatus_SUCCESS;
}

int PyMOL_FreeResultArray(CPyMOL *I,void *array)
{
  if(array) {
    VLAFreeP(array);
    return PyMOLstatus_SUCCESS;
  } else {
    return PyMOLstatus_FAILURE; 
  }
}

PyMOLreturn_status PyMOL_CmdSetView(CPyMOL *I, float *view, int view_len,
                                    float animate, int quiet)
{
  PyMOLreturn_status result;
  SceneViewType tmp;
  PYMOL_API_LOCK
  if(view_len>=18) {
    int a;
    UtilZeroMem(tmp,sizeof(tmp));
    tmp[15]=1.0F;
    for(a=0;a<3;a++) {
      tmp[a]=view[a];
      tmp[a+4]=view[a+3];
      tmp[a+8]=view[a+6];
      tmp[a+16]=view[a+9];
      tmp[a+19]=view[a+12];
      tmp[a+22]=view[a+15];
    }
    SceneSetView(I->G,tmp,quiet,animate,0);  /* TO DO -- add hand to the API */
    result.status = get_status_ok(true);
  } else {
    result.status = get_status_ok(false);
  }
  PYMOL_API_UNLOCK
  return result;
}

PyMOLreturn_float_array PyMOL_CmdGetView(CPyMOL *I,int quiet)
{
  PyMOLreturn_float_array result;
  SceneViewType tmp;
  PYMOL_API_LOCK
  result.size = 18;
  result.array = VLAlloc(float,result.size);
  if(result.array) {
    int a;
    SceneGetView(I->G,tmp);
    for(a=0;a<3;a++) {
      result.array[a]=tmp[a];
      result.array[a+3]=tmp[a+4];
      result.array[a+6]=tmp[a+8];
      result.array[a+9]=tmp[a+16];
      result.array[a+12]=tmp[a+19];
      result.array[a+15]=tmp[a+22];
    }
    result.status = get_status_ok(true);
  } else {
    result.status = get_status_ok(false);
  }
  PYMOL_API_UNLOCK
  return result;
}

PyMOLreturn_float_array PyMOL_CmdAlign(CPyMOL *I, char *source, char *target, float cutoff, 
                                 int cycles, float gap, float extend, int max_gap, 
                                 char *object, char *matrix, int source_state, int target_state, 
                                 int quiet, int max_skip) 
{
  PyMOLreturn_float_array result;
  
  PYMOL_API_LOCK
  OrthoLineType s2="",s3="";
  int ok = false;
  ExecutiveRMSInfo rms_info;
  result.size = 7;
  result.array = VLAlloc(float,result.size);
  if(!result.array) {
    ok=false;
  } else {
    ok = ((SelectorGetTmp(I->G,source,s2)>=0) &&
          (SelectorGetTmp(I->G,target,s3)>=0));
    if(ok) {
      ok = ExecutiveAlign(I->G,s2,s3,matrix,gap,extend,max_gap,
                                       max_skip,cutoff,cycles,quiet,object,
                                       source_state-1, target_state-1,
                                       &rms_info);
      if(ok) {
        result.array[0] = rms_info.final_rms;
        result.array[1] = rms_info.final_n_atom;
        result.array[2] = rms_info.n_cycles_run;
        result.array[3] = rms_info.initial_rms;
        result.array[4] = rms_info.initial_n_atom;
        result.array[5] = rms_info.raw_alignment_score;
        result.array[6] = rms_info.n_residues_aligned;
      }
    }
  }
  SelectorFreeTmp(I->G,s2);
  SelectorFreeTmp(I->G,s3);
  result.status = get_status_ok(ok);
  if(!ok) { 
    VLAFreeP(result.array);
  }
  PYMOL_API_UNLOCK
  
  return result;
}

PyMOLreturn_status PyMOL_CmdDelete(CPyMOL *I,char *name,int quiet)
{
  PYMOL_API_LOCK
  ExecutiveDelete(I->G, name);
  PYMOL_API_UNLOCK
 return return_status_ok(true); /* TO DO: return a real result */
}

PyMOLreturn_status PyMOL_CmdZoom(CPyMOL *I,char *selection, float buffer,
                              int state, int complete, float animate, int quiet)
{
  int ok=false;
  PYMOL_API_LOCK
  ok = ExecutiveWindowZoom(I->G, selection, buffer, state-1, 
                               complete, animate, quiet);
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdOrient(CPyMOL *I,char *selection, float buffer, 
                                int state, int complete, float  animate, int quiet)
{
  int ok=true;
  PYMOL_API_LOCK
  double m[16];
  OrthoLineType s1;
  SelectorGetTmp(I->G,selection,s1);
  if(ExecutiveGetMoment(I->G,s1,m,state))
    ExecutiveOrient(I->G,s1,m,state-1,animate,complete,buffer,quiet); /* TODO STATUS */
  else
    ok=false;
  SelectorFreeTmp(I->G,s1);
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdCenter(CPyMOL *I,char *selection, int state, int origin, float animate, int quiet)
{
  int ok = false;
  PYMOL_API_LOCK
  ok = ExecutiveCenter(I->G,selection,state-1,origin,animate,NULL,quiet);
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}


PyMOLreturn_status PyMOL_CmdOrigin(CPyMOL *I,char *selection, int state, int quiet)
{
  int ok=true;
  PYMOL_API_LOCK
  OrthoLineType s1;
  float v[3] = { 0.0F, 0.0F, 0.0F };
  SelectorGetTmp(I->G,selection,s1);
  ok = ExecutiveOrigin(I->G,s1,true,"",v,state-1); /* TODO STATUS */
  SelectorFreeTmp(I->G,s1);
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdOriginAt(CPyMOL *I,float x, float y, float z, int quiet)
{
  int ok=true;
  PYMOL_API_LOCK
  float v[3];
  v[0]=x;v[1]=y;v[2]=z;
  ok = ExecutiveOrigin(I->G,"",true,"",v,0); /* TODO STATUS */
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

static OVreturn_word get_rep_id(CPyMOL *I,char *representation)
{
  OVreturn_word result;

  if(!OVreturn_IS_OK( (result = OVLexicon_BorrowFromCString(I->Lex,representation))))
    return result;
  return OVOneToOne_GetForward(I->Rep,result.word);
}

static OVreturn_word get_setting_id(CPyMOL *I,char *setting)
{
  OVreturn_word result;
  result = OVLexicon_BorrowFromCString(I->Lex,setting);
  if(!OVreturn_IS_OK( (result = OVLexicon_BorrowFromCString(I->Lex,setting))))
    return result;
  return OVOneToOne_GetForward(I->Setting,result.word);
}

static OVreturn_word get_clip_id(CPyMOL *I,char *clip)
{
  OVreturn_word result;
  result = OVLexicon_BorrowFromCString(I->Lex,clip);
  if(!OVreturn_IS_OK( (result = OVLexicon_BorrowFromCString(I->Lex,clip))))
    return result;
  return OVOneToOne_GetForward(I->Clip,result.word);
}

static OVreturn_word get_select_list_mode(CPyMOL *I,char *mode)
{
  OVreturn_word result;
  result = OVLexicon_BorrowFromCString(I->Lex,mode);
  if(!OVreturn_IS_OK( (result = OVLexicon_BorrowFromCString(I->Lex,mode))))
    return result;
  return OVOneToOne_GetForward(I->SelectList,result.word);
}

PyMOLreturn_status PyMOL_CmdClip(CPyMOL *I,char *mode, float amount, char *selection, int state, int quiet)
{
  int ok=true;
  PYMOL_API_LOCK
  OrthoLineType s1;
  OVreturn_word clip_id;
  if(OVreturn_IS_OK( (clip_id= get_clip_id(I,mode)))) {
    SelectorGetTmp(I->G,selection,s1);
    SceneClip(I->G,clip_id.word,amount,s1,state-1);
    SelectorFreeTmp(I->G,s1);
  }
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdSelect(CPyMOL *I,char *name, char *selection, int quiet)
{
  int ok;
  PYMOL_API_LOCK
  ok = SelectorCreate(I->G,name,selection,NULL,quiet,NULL);
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdSelectList(CPyMOL *I,char *name, char *object, int *list, int list_len, int state, char *mode, int quiet)
{
  PyMOLreturn_status result = { PyMOLstatus_FAILURE };
  PYMOL_API_LOCK
  OVreturn_word mode_id;
  if(OVreturn_IS_OK( (mode_id= get_select_list_mode(I,mode)))) {
    result.status = ExecutiveSelectList(I->G,name, object,  list, list_len, state-1, mode_id.word, quiet);
  }
  PYMOL_API_UNLOCK
  return result;
}

PyMOLreturn_status PyMOL_CmdShow(CPyMOL *I,char *representation, char *selection, int quiet)
{
  int ok=true;
  PYMOL_API_LOCK
  OrthoLineType s1;
  OVreturn_word rep_id;
  if(OVreturn_IS_OK( (rep_id= get_rep_id(I,representation)))) {
    SelectorGetTmp(I->G,selection,s1);
    ExecutiveSetRepVisib(I->G,s1,rep_id.word,true);
    SelectorFreeTmp(I->G,s1);
  } else {
    ok=false;
  }
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdHide(CPyMOL *I,char *representation, char *selection, int quiet)
{
  int ok=true;
  PYMOL_API_LOCK
  OrthoLineType s1;
  OVreturn_word rep_id;
  if(OVreturn_IS_OK( (rep_id = get_rep_id(I,representation)))) {
    SelectorGetTmp(I->G,selection,s1);
    ExecutiveSetRepVisib(I->G,s1,rep_id.word,false);
    SelectorFreeTmp(I->G,s1);
  } else {
    ok=false;
  }
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdEnable(CPyMOL *I,char *name,int quiet)
{
  int ok = false; 
  PYMOL_API_LOCK
  if(name[0]=='(') {
    OrthoLineType s1;
    ok = (SelectorGetTmp(I->G,name,s1)>=0);
    if(ok) ok = ExecutiveSetOnOffBySele(I->G,s1,true);
    SelectorFreeTmp(I->G,s1);
  }
  ok = ExecutiveSetObjVisib(I->G,name,true);
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdDisable(CPyMOL *I,char *name,int quiet)
{
  int ok = false;
  PYMOL_API_LOCK
  if(name[0]=='(') {
    OrthoLineType s1;
    ok = (SelectorGetTmp(I->G,name,s1)>=0);
    if(ok) ok = ExecutiveSetOnOffBySele(I->G,s1,false);
    SelectorFreeTmp(I->G,s1);
  } else {
    ok = ExecutiveSetObjVisib(I->G,name,false);
  }
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdSet(CPyMOL *I,char *setting, char *value, char *selection, int state, int quiet, int side_effects)
{
  int ok=true;
  PYMOL_API_LOCK
  OVreturn_word setting_id;
  if(OVreturn_IS_OK( (setting_id = get_setting_id(I,setting)))) {
    ExecutiveSetSettingFromString(I->G, setting_id.word, value, selection,
                                  state-1, quiet, side_effects);
  }
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdColor(CPyMOL *I,char *color, char *selection, int flags, int quiet)
{
  int ok=true;
  PYMOL_API_LOCK
  OrthoLineType s1 = "";
  
  SelectorGetTmp(I->G,selection,s1);
  ok = ExecutiveColor(I->G,s1,color,flags,quiet);
  SelectorFreeTmp(I->G,s1);
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdReinitialize(CPyMOL *I)
{
  int ok;
  PYMOL_API_LOCK
  ok = ExecutiveReinitialize(I->G);
  PYMOL_API_UNLOCK
  return return_status_ok(ok);
}

PyMOLreturn_float PyMOL_CmdGetDistance(CPyMOL *I,
                                        char *selection1,
                                        char *selection2, 
                                        int state,
                                        int quiet)
{
  int ok=true;
  OrthoLineType s1="",s2="";
  PyMOLreturn_float result;
  PYMOL_API_LOCK

  if(ok) ok = (SelectorGetTmp(I->G,selection1,s1)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection2,s2)>=0);

  if(ok) {
    ok = ExecutiveGetDistance(I->G,s1,s2,&result.value,state);
    result.status = get_status_ok(ok);    
  } else {
    result.status = PyMOLstatus_FAILURE;
    result.value = -1.0F;
  }
  PYMOL_API_UNLOCK
  SelectorFreeTmp(I->G,s1);
  SelectorFreeTmp(I->G,s2);
  return result;
}

PyMOLreturn_float PyMOL_CmdDistance(CPyMOL *I,
                                    char *name,
                                    char *selection1,
                                    char *selection2, 
                                    int mode,
                                    float cutoff,
                                    int label, 
                                    int reset,
                                    int zoom,
                                    int state,
                                    int quiet)
{
  int ok=true;
  OrthoLineType s1="",s2="";
  PyMOLreturn_float result;
  PYMOL_API_LOCK

  if(ok) ok = (SelectorGetTmp(I->G,selection1,s1)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection2,s2)>=0);

  if(ok) {
    ok = ExecutiveDist(I->G,&result.value,name,s1,s2,
                       mode,cutoff,label,quiet,reset,state,zoom);
    result.status = get_status_ok(ok);
  } else {
    result.status = PyMOLstatus_FAILURE;
    result.value = -1.0F;
  }
  PYMOL_API_UNLOCK
  SelectorFreeTmp(I->G,s1);
  SelectorFreeTmp(I->G,s2);
  return result;
}

PyMOLreturn_float PyMOL_CmdGetAngle(CPyMOL *I,
                                     char *selection1,
                                     char *selection2,
                                     char *selection3,
                                     int state,
                                     int quiet)
{
  int ok=true;
  OrthoLineType s1="",s2="",s3="";
  PyMOLreturn_float result;
  PYMOL_API_LOCK

  if(ok) ok = (SelectorGetTmp(I->G,selection1,s1)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection2,s2)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection3,s3)>=0);

  if(ok) {
    ok = ExecutiveGetAngle(I->G,s1,s2,s3,&result.value,state);
    result.status = get_status_ok(ok);
  } else {
    result.status = PyMOLstatus_FAILURE;
    result.value = 0.0F;
  }
  PYMOL_API_UNLOCK
  SelectorFreeTmp(I->G,s1);
  SelectorFreeTmp(I->G,s2);
  SelectorFreeTmp(I->G,s3);
  return result;
}

PyMOLreturn_float PyMOL_CmdAngle(CPyMOL *I,
                                 char *name,
                                 char *selection1,
                                 char *selection2, 
                                 char *selection3, 
                                 int mode,
                                 int label, 
                                 int reset,
                                 int zoom,
                                 int state,
                                 int quiet)
{
  int ok=true;
  OrthoLineType s1="",s2="",s3="";
  PyMOLreturn_float result;
  PYMOL_API_LOCK

  if(ok) ok = (SelectorGetTmp(I->G,selection1,s1)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection2,s2)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection3,s3)>=0);

  if(ok) {
    ok = ExecutiveAngle(I->G,&result.value,name,s1,s2,s3,
                       mode,label,reset,zoom,quiet,state);
    result.status = get_status_ok(ok);
  } else {
    result.status = PyMOLstatus_FAILURE;
    result.value = -1.0F;
  }
  PYMOL_API_UNLOCK
  SelectorFreeTmp(I->G,s1);
  SelectorFreeTmp(I->G,s2);
  SelectorFreeTmp(I->G,s3);
  return result;
}


PyMOLreturn_float PyMOL_CmdGetDihedral(CPyMOL *I,
                                        char *selection1,
                                        char *selection2,
                                        char *selection3,
                                        char *selection4,
                                        int state,
                                        int quiet)
{
  int ok=true;
  OrthoLineType s1="",s2="",s3="",s4="";
  PyMOLreturn_float result;
  PYMOL_API_LOCK

  if(ok) ok = (SelectorGetTmp(I->G,selection1,s1)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection2,s2)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection3,s3)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection4,s4)>=0);

   if(ok) {
    ok = ExecutiveGetDihe(I->G,s1,s2,s3,s4,&result.value,state);
    result.status = get_status_ok(ok);
 } else {
    result.status = PyMOLstatus_FAILURE;
    result.value = 0.0F;
  }
  PYMOL_API_UNLOCK
  SelectorFreeTmp(I->G,s1);
  SelectorFreeTmp(I->G,s2);
  SelectorFreeTmp(I->G,s3);
  SelectorFreeTmp(I->G,s4);
  return result;
}

PyMOLreturn_float PyMOL_CmdDihedral(CPyMOL *I,
                                    char *name,
                                    char *selection1,
                                    char *selection2, 
                                    char *selection3, 
                                    char *selection4, 
                                    int mode,
                                    int label, 
                                    int reset,
                                    int zoom,
                                    int state,
                                    int quiet)
{
  int ok=true;
  OrthoLineType s1="",s2="",s3="",s4="";
  PyMOLreturn_float result;
  PYMOL_API_LOCK
    
  if(ok) ok = (SelectorGetTmp(I->G,selection1,s1)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection2,s2)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection3,s3)>=0);
  if(ok) ok = (SelectorGetTmp(I->G,selection4,s4)>=0);
  
  if(ok) {
    ok = ExecutiveDihedral(I->G,&result.value,name,s1,s2,s3,s4,
                       mode,label,reset,zoom,quiet,state);
    result.status = get_status_ok(ok);
  } else {
    result.status = PyMOLstatus_FAILURE;
    result.value = -1.0F;
  }
  PYMOL_API_UNLOCK
  SelectorFreeTmp(I->G,s1);
  SelectorFreeTmp(I->G,s2);
  SelectorFreeTmp(I->G,s3);
  SelectorFreeTmp(I->G,s4);
  return result;
}

static PyMOLreturn_status Loader(CPyMOL *I,char *content,  char *content_type, 
                                 int content_length, char *content_format, 
                                 char *object_name, int state, 
                                 int discrete, int finish, 
                                 int quiet, int multiplex, int zoom)
{
  OVreturn_word result;
  int type_code = 0;
  int format_code = 0;
  int ok = true;
  WordType obj_name;
  
  if(!OVreturn_IS_OK( (result= OVLexicon_BorrowFromCString(I->Lex,content_type))))
    ok = false;
  else
    type_code = result.word;

  if(ok) {
    if(!OVreturn_IS_OK( (result= OVLexicon_BorrowFromCString(I->Lex,content_format))))
      ok = false;
    else
      format_code = result.word;
  }

  if(ok) {
    if((type_code != I->lex_filename) &&
       (type_code != I->lex_string) &&
       (type_code != I->lex_raw) &&
       (type_code != I->lex_cgo)) {
      
      ok = false;
    }
  }
  if(ok) {
    
    /* handling of multiplex option */
    
    if(multiplex==-2) /* use setting default value */
      multiplex = SettingGetGlobal_i(I->G,cSetting_multiplex);
    if(multiplex<0) /* default behavior is not to multiplex */
      multiplex = 0;
    
    /* handing of discete option */
    
    if(discrete<0) {/* use default discrete behavior for the file format 
                     * this will be the case for MOL2 and SDF */ 
      if(multiplex==1) /* if also multiplexing, then default discrete
                        * behavior is not load as discrete objects */
        discrete=0;
      else
        discrete=1; /* otherwise, allow discrete to be the default */
    }
    
    { /* if object_name is blank and content is a filename, then 
         compute the object_name from the file prefix */
      if((!object_name[0])&&(type_code == I->lex_filename)) {
        char *start, *stop;
        stop = start = content + strlen(content)-1;
        while(start>content) { /* known path separators */
          if((start[-1]==':')||
             (start[-1]=='\'')||
             (start[-1]=='/'))
            break;
          start--;
        }
        while(stop>start) {
          if(*stop=='.')
            break;
          stop--;
        }
        if(stop==start)
          stop = content + strlen(content);
        if((stop-start) >=sizeof(WordType))
          stop = start+sizeof(WordType)-1;
        { 
          char *p,*q;
          p=start;
          q=obj_name;
          while(p<stop) {
            *(q++)=*(p++);
          }
          *q=0;
          object_name = obj_name;
        }
      }
    }
    {
      int pymol_content_type = cLoadTypeUnknown;
      CObject *existing_object = NULL;

      /* convert text format strings into integral load types */

      if(format_code == I->lex_pdb) {
        if((type_code == I->lex_raw) ||(type_code == I->lex_string))
          pymol_content_type = cLoadTypePDBStr;
        else if( type_code == I->lex_filename)
          pymol_content_type = cLoadTypePDB;
      } else if(format_code == I->lex_mol2) {
        if((type_code == I->lex_raw) || (type_code == I->lex_string))
          pymol_content_type = cLoadTypeMOL2Str;
        else if( type_code == I->lex_filename)
          pymol_content_type = cLoadTypeMOL2;
      } else if(format_code == I->lex_mol) {
        if((type_code == I->lex_raw) || (type_code == I->lex_string))
          pymol_content_type = cLoadTypeMOLStr;
        else if( type_code == I->lex_filename)
          pymol_content_type = cLoadTypeMOL;
      } else if(format_code == I->lex_sdf) {
        if((type_code == I->lex_raw) || (type_code == I->lex_string))
          pymol_content_type = cLoadTypeSDF2Str;
        else if( type_code == I->lex_filename)
          pymol_content_type = cLoadTypeSDF2;
      } else if(format_code == I->lex_ccp4) {
        if((type_code == I->lex_raw) || (type_code == I->lex_string))
          pymol_content_type = cLoadTypeCCP4Str;
      } else if(format_code == I->lex_xplor) {
        if((type_code == I->lex_raw) || (type_code == I->lex_string))
          pymol_content_type = cLoadTypeXPLORStr;
      } else if(format_code == I->lex_cgo) {
        if(type_code == I->lex_cgo) {
          pymol_content_type = cLoadTypeCGO;
        }
      }

      if(pymol_content_type != cLoadTypeUnknown) {
        existing_object = ExecutiveGetExistingCompatible(I->G,
                                                         object_name,
                                                         pymol_content_type);
      }

      /* measure the length if it wasn't provided */

      if(content_length<0) {
        if(type_code == I->lex_string)
          content_length = strlen(content);
      }

      switch(pymol_content_type) {
      case cLoadTypePDB:
      case cLoadTypePDBStr:
      case cLoadTypeMOL:
      case cLoadTypeMOLStr:
      case cLoadTypeMOL2:
      case cLoadTypeMOL2Str:
      case cLoadTypeSDF2:
      case cLoadTypeSDF2Str:
      case cLoadTypeXPLORMap:
      case cLoadTypeXPLORStr:
      case cLoadTypeCCP4Map:
      case cLoadTypeCCP4Str:
      case cLoadTypeCGO:
        ok = ExecutiveLoad(I->G, existing_object, 
                           content, content_length, 
                           pymol_content_type,
                           object_name, 
                           state-1,  zoom,
                           discrete, finish,
                           multiplex, quiet);
        break;
      default:
        ok=false;
        break;
      }
    }
  }
  return return_status_ok(ok);
}

PyMOLreturn_status PyMOL_CmdLoad(CPyMOL *I,char *content,  
                                        char *content_type,
                                        char *content_format, 
                                        char *object_name, int state, 
                                        int discrete, int finish, 
                                        int quiet, int multiplex, int zoom)
{
  PyMOLreturn_status status;
  PYMOL_API_LOCK
  status = Loader(I,content, content_type, -1, content_format, object_name, 
                state, discrete, finish, quiet, multiplex, zoom);
  PYMOL_API_UNLOCK
  return status;
}
     
PyMOLreturn_status PyMOL_CmdLoadRaw(CPyMOL *I,char *content, 
                                    int content_length,
                                    char *content_format, 
                                    char *object_name, int state, 
                                    int discrete, int finish, 
                                    int quiet, int multiplex, int zoom)
{
  PyMOLreturn_status status;
  PYMOL_API_LOCK
  status = Loader(I,content, "raw", content_length, content_format,
                object_name, state, discrete, finish, quiet, multiplex, zoom);
  PYMOL_API_UNLOCK
  return status;
}

PyMOLreturn_status PyMOL_CmdLoadCGO(CPyMOL *I,float *content, 
                                    int content_length,
                                    char *object_name, int state, 
                                    int quiet, int zoom)
{
  PyMOLreturn_status status;
  PYMOL_API_LOCK
  status = Loader(I, (char*)content, "cgo", content_length, "cgo",
                  object_name, state, 0, 1, quiet, 0, zoom);
  PYMOL_API_UNLOCK
  return status;
}

static const CPyMOLOptions Defaults = {
 true, /* pmgui */
#ifndef _PYMOL_NOPY
  true, /* internal_gui*/
#else
  false, 
#endif
#ifndef _PYMOL_NOPY
  true, /* show_splash */
#else
  false,
#endif
#ifndef _PYMOL_NOPY
  1,   /* internal_feedback */
#else
  0, 
#endif
  true, /* security */
  false, /* game mode */
  0, /* force_stereo */
  640, /* winX */
  480, /* winY */
  false, /* blue_line */
  0, /* winPX */
  175, /* winPY */
  true, /* external_gui */
  true, /* siginthand */
  false, /* reuse helper */
  false, /* auto reinitialize */
  false, /* keep thread alive */
  false, /* quiet */
  false, /* incentive product */
  "", /* after_load_script */
  0, /* multisample */
  1, /* window_visible */
  0, /* read_stdin */
  0, /* presentation */
  0, /* defer builds mode */
  0, /* full screen mode */
  -1, /* sphere mode */
  0, /* stereo capable */
  0, /* passive stereo */
  -1, /* zoom mode */
};

CPyMOLOptions *PyMOLOptions_New(void)
{
  CPyMOLOptions *result = NULL;
  result = Calloc(CPyMOLOptions,1);
  if(result)
    *result = Defaults;
  return result;
}

#ifndef _PYMOL_NOPY
static void init_python(int argc, char *argv[])
{
    Py_Initialize();
    if(argv) {
	  PySys_SetArgv(argc,argv);
    }

/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifdef _MACPYMOL_XCODE
    /* there appears to be a bug or a race collection in the garbage
       collector of the Python version that ships with Mac OS --
       better to potentially leak a little RAM than crash unexpectedly
       in a _PyObject_GC_Del call.
       BTW: PyMOL doesn't itself need the GC, but end-user code
       might. */
    PyRun_SimpleString("import gc");
    PyRun_SimpleString("gc.disable()");
#endif
/* END PROPRIETARY CODE SEGMENT */

	PyEval_InitThreads();
	
#ifdef _PYMOL_OWN_INTERP
	{ /* NOTE this doesn't work 'cause we can't unpack code in restricted environments! */
	
	   /* get us a brand new interpreter, independent of any other */
	   
	   PyThreadState *tstate = Py_NewInterpreter();
	   
	   /* now release the first interpreter and use the second */
       PyThreadState_Swap(tstate);
	}
#endif

    PyUnicode_SetDefaultEncoding("utf-8"); /* is this safe & legal? */
	PyRun_SimpleString("import sys");
	PyRun_SimpleString("import os");
	PyRun_SimpleString("sys.path.insert(0,os.environ['PYMOL_PATH']+'/modules')");

/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifdef _MACPYMOL_XCODE
    { /* add an architecture-dependent search path for platform-specific binary modules
		here we're cheating by using endianness instead of figuring out how to get the
		true architecture from OS X */
		unsigned int val = 0x01020304;
		unsigned int *i_ptr=&val;
		char *c_ptr = (char*)i_ptr;
		if(*c_ptr==0x01) {
			PyRun_SimpleString("sys.path.insert(0,os.environ['PYMOL_PATH']+'/modules/ppc')");
		} else {
			PyRun_SimpleString("sys.path.insert(0,os.environ['PYMOL_PATH']+'/modules/i386')");
		}
	}
#endif
/* END PROPRIETARY CODE SEGMENT */

	PyRun_SimpleString("import __main__");
    {
		PyObject *P_main = PyImport_AddModule("__main__");
		if(!P_main) printf("PyMOL can't find '__main__'\n");

		/* set up a dry run through 'import pymol' */
 
		PyObject_SetAttrString(P_main,"pymol_launch",PyInt_FromLong(3));
    }
 
    /* initiate PyMOL dry run to create __main__.pymol */
	
 	PyRun_SimpleString("import pymol");
	
    /* parse arguments */

	PyRun_SimpleString("pymol.invocation.parse_args(sys.argv)");

}

CPyMOLOptions *PyMOLOptions_NewWithPython(int argc, char *argv[])
{
  CPyMOLOptions *result = PyMOLOptions_New();
  
  /* use Python to parse options based on the command line */
  
  init_python(argc,argv);
  PGetOptions(result);
  return result;
}
#endif

void PyMOLOptions_Free(CPyMOLOptions *options)
{
  FreeP(options);
}

void PyMOL_ResetProgress(CPyMOL *I)
{
  I->ProgressChanged = true;
  UtilZeroMem(I->Progress, sizeof(int)*6);
}

void PyMOL_SetProgress(CPyMOL *I,int offset, int current, int range)
{
  switch(offset) {
  case PYMOL_PROGRESS_SLOW:
  case PYMOL_PROGRESS_MED:
  case PYMOL_PROGRESS_FAST:
    if(current!=I->Progress[offset]) {
      I->Progress[offset] = current;
      I->ProgressChanged = true;
    }
    if(range!=I->Progress[offset+1]) {
      I->Progress[offset+1] = range;
      I->ProgressChanged = true;
    }
  }
}

int PyMOL_GetProgress(CPyMOL *I,int *progress,int reset)
{
  int a;
  int result = I->ProgressChanged;
  for(a=0;a<PYMOL_PROGRESS_SIZE;a++) {
    progress[a] = I->Progress[a];
  }
  if(reset) 
    I->ProgressChanged=false;
  return result;
}

int PyMOL_GetProgressChanged(CPyMOL *I,int reset)
{
  int result = I->ProgressChanged;
  if(reset)
    I->ProgressChanged=false;
  return result;
}

static CPyMOL *_PyMOL_New(void)
{
  CPyMOL *result = NULL;

  /* allocate global container */

  if( (result = Calloc(CPyMOL,1)) ) { /* all values initialized to zero */

    if( (result->G = Calloc(PyMOLGlobals,1)) ) {
      
      result->G->PyMOL = result; /* store the instance pointer */

      result->BusyFlag = false;
      result->InterruptFlag = false;
      PyMOL_ResetProgress(result);

      #ifndef _PYMOL_NOPY
      /* temporary global pointer for the transition period */
      TempPyMOLGlobals=result->G;
      #endif

      /* continue initialization */

    } else {
      FreeP(result);
    }
  }
  return result;
}
 
static void _PyMOL_Config(CPyMOL *I)
{
    I->G->HaveGUI = I->G->Option->pmgui;
    I->G->Security = I->G->Option->security;
}

CPyMOL *PyMOL_New(void)
{
  CPyMOL *result = _PyMOL_New();
  if(result && result->G) {
    result->G->Option = Calloc(CPyMOLOptions,1);
    if(result->G->Option)
      (*result->G->Option) = Defaults;
    _PyMOL_Config(result);
  }
  return result;
}

CPyMOL *PyMOL_NewWithOptions(CPyMOLOptions *option)
{
  CPyMOL *result = _PyMOL_New();
  if(result && result->G) {
    result->G->Option = Calloc(CPyMOLOptions,1);
    if(result->G->Option)
      *(result->G->Option) = *option;
    _PyMOL_Config(result);
  }
  result->G->StereoCapable = option->stereo_capable;
  return result;
}


void PyMOL_Start(CPyMOL *I)
{
  PyMOLGlobals *G=I->G;

  G->Context = OVContext_New();
  G->Lexicon = OVLexicon_New(G->Context->heap);

  if(OVreturn_IS_ERROR(PyMOL_InitAPI(I))) {
    printf("ERROR: PyMOL internal C API initialization failed.\n");
  }

  MemoryCacheInit(G);
  FeedbackInit(G,G->Option->quiet);
  WordInit(G);
  UtilInit(G);
  ColorInit(G);
  CGORendererInit(G);
  SettingInitGlobal(G,true,true);  
  SettingSetGlobal_i(G,cSetting_internal_gui,G->Option->internal_gui);
  SettingSetGlobal_i(G,cSetting_internal_feedback,G->Option->internal_feedback);
  TextureInit(G);
  TypeInit(G);
  TextInit(G);
  CharacterInit(G);
  SphereInit(G);
  OrthoInit(G,G->Option->show_splash);
  WizardInit(G); /* must come after ortho */
  SceneInit(G);
  MovieInit(G);
  SelectorInit(G);
  SeqInit(G);
  SeekerInit(G);
  ButModeInit(G);
  ControlInit(G);
  AtomInfoInit(G);
  SculptCacheInit(G);
  VFontInit(G);
  ExecutiveInit(G);
  IsosurfInit(G);
  TetsurfInit(G);
  EditorInit(G);

#ifdef TRACKER_UNIT_TEST
  TrackerUnitTest(G);
#endif

/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifdef _MACPYMOL_XCODE
	SettingSetGlobal_b(G,cSetting_stereo_double_pump_mono, true);
    if(G->Option->stereo_capable) {
		SettingSetGlobal_i(G,cSetting_stereo_mode, 1); 
       }
    /*    	SettingSetGlobal_i(G,cSetting_show_progress, 0);  */
#endif
/* END PROPRIETARY CODE SEGMENT */

  I->RedisplayFlag = true;
  G->Ready = true; 
}

#ifndef _PYMOL_NOPY

/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifdef _MACPYMOL_XCODE
void init_cmd(void);
void initExtensionClass(void);
void initsglite(void);
void init_champ(void);
#endif
/* END PROPRIETARY CODE SEGMENT */

void PyMOL_StartWithPython(CPyMOL *I)
{
	PyMOL_Start(I);
	
	{
		PyObject *P_main = PyImport_AddModule("__main__");
		if(!P_main) printf("PyMOL can't find '__main__'\n");

		/* set up for embedded-style launch */
		PyObject_SetAttrString(P_main,"pymol_launch",PyInt_FromLong(5));
    }
	
	/* initialize our embedded C modules */

/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifdef _MACPYMOL_XCODE	
    init_cmd();
	initExtensionClass();
    initsglite();
	init_champ();
#endif
/* END PROPRIETARY CODE SEGMENT */

	/* launch pymol's Python subsystems */
	
	PyRun_SimpleString("reload(pymol)");
	
	/* now locate all the C to Python function hooks and objects we need */
	
	PInit(I->G);
	
	/* and begin the initialization sequence */
	
	I->PythonInitStage = 1;
	
/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifdef _MACPYMOL_XCODE
  MacPyMOLOption = I->G->Option;
  MacPyMOLReady = &I->G->Ready;
#endif  
/* END PROPRIETARY CODE SEGMENT */
}
#endif

void PyMOL_Stop(CPyMOL *I)
{
  PyMOLGlobals *G=I->G;
  G->Terminating=true;
  TetsurfFree(G);
  IsosurfFree(G);
  WizardFree(G);
  SceneCleanupStereo(G);
  EditorFree(G);
  ExecutiveFree(G);
  VFontFree(G);
  SculptCacheFree(G);
  AtomInfoFree(G);
  ButModeFree(G);
  ControlFree(G);
  SeekerFree(G);
  SeqFree(G);
  SelectorFree(G);
  MovieFree(G);
  SceneFree(G);
  OrthoFree(G);
  SettingFreeGlobal(G);
  CharacterFree(G);
  TextFree(G);
  TypeFree(G);
  TextureFree(G);
  SphereFree(G);
  PFree();
  CGORendererFree(G);
  ColorFree(G);
  UtilFree(G);
  WordFree(G);
  FeedbackFree(G);
  MemoryCacheDone(G);
  
  PyMOL_PurgeAPI(I);
  /*    printf("%d \n", OVLexicon_GetNActive(G->Lexicon));*/
  OVLexicon_Del(G->Lexicon);
  OVContext_Del(G->Context);   
}



void PyMOL_Free(CPyMOL *I)
{
  PYMOL_API_LOCK
    /* take PyMOL down gracefully */
    PyMOLOptions_Free(I->G->Option);
  FreeP(I->G);
#ifndef _PYMOL_NOPY
#ifdef _PYMOL_OWN_INTERP
  if(I->PythonInitStage) { /* shut down this interpreter gracefully, then free the GIL for others to use */
    PBlock();
    { /* should this be moved into a PDestroy?() to clear out the thread record too? */
      PyThreadState *tstate = PyEval_SaveThread();
      PyEval_AcquireThread(tstate);
      Py_EndInterpreter(tstate);
      PyEval_ReleaseLock();
	}
  }
#endif
#endif
  FreeP(I);
  return;
  PYMOL_API_UNLOCK;
}

struct _PyMOLGlobals *PyMOL_GetGlobals(CPyMOL *I)
{
  return I->G;
}

void PyMOL_Draw(CPyMOL *I)
{
  PYMOL_API_LOCK
  
  PyMOLGlobals *G = I->G;

  if(I->DraggedFlag) {
    if(ControlIdling(I->G)) {
      ExecutiveSculptIterateAll(I->G);
    }
    I->DraggedFlag = false;
  }
  if(G->HaveGUI) {

    PyMOL_PushValidContext(I);

    /* get us into a well defined GL state */

    /*glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();*/

    glDisable(GL_ALPHA_TEST);
    glDisable(GL_AUTO_NORMAL);
    glDisable(GL_BLEND);
    glDisable(GL_COLOR_LOGIC_OP);
    glDisable(GL_COLOR_MATERIAL);
    glDisable(GL_CULL_FACE);

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_DITHER);
    glDisable(GL_FOG);
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);
    glDisable(GL_LIGHT1);
    glDisable(GL_LINE_SMOOTH);
    glDisable(GL_NORMALIZE);
    glDisable(GL_POLYGON_SMOOTH);
    
/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifdef _MACPYMOL_XCODE
    { /* on a mac, this can change if we've switched contexts...*/
      GLboolean state;
      glGetBooleanv(GL_STEREO, &state);
      G->StereoCapable = (int) state;
    }
#endif
/* END PROPRIETARY CODE SEGMENT */
    
  }
  
  I->RedisplayFlag = false;
  
  OrthoBusyPrime(G);
  ExecutiveDrawNow(G);

  if(G->HaveGUI) PyMOL_PopValidContext(I);
  
  PYMOL_API_UNLOCK
  
}

void PyMOL_Key(CPyMOL *I,unsigned char k, int x, int y, int modifiers)
{
  PYMOL_API_LOCK
  
  PyMOLGlobals *G = I->G;

  if(!WizardDoKey(G,k,x,y,modifiers))
    OrthoKey(G,k,x,y,modifiers);
  PYMOL_API_UNLOCK
}


void PyMOL_Special(CPyMOL *I,int k, int x, int y, int modifiers)
{
  PYMOL_API_LOCK
  
  PyMOLGlobals *G = I->G;

  int grabbed = false;
  char buffer[255];
  
  if(!grabbed)
    grabbed = WizardDoKey(G,(unsigned char)k,x,y,modifiers);
  
  switch(k) {
  case P_GLUT_KEY_UP:
  case P_GLUT_KEY_DOWN:
    grabbed=1;
    OrthoSpecial(G,k,x,y,modifiers);
    break;
  case P_GLUT_KEY_LEFT:
  case P_GLUT_KEY_RIGHT:      
    if(OrthoArrowsGrabbed(G)) {
      grabbed=1;
      OrthoSpecial(G,k,x,y,modifiers);
    }
    break;
  }
  
  if(!grabbed) {
    sprintf(buffer,"_special %d,%d,%d,%d",k,x,y,modifiers);
    PLog(buffer,cPLog_pml);
    PParse(buffer);
    PFlush();
  }
  PYMOL_API_UNLOCK
}

void PyMOL_Reshape(CPyMOL *I,int width, int height, int force)
{
  PYMOL_API_LOCK
  PyMOLGlobals *G = I->G;


  G->Option->winX = width;
  G->Option->winY = height;

  OrthoReshape(G,width,height,force);
  PYMOL_API_UNLOCK
}

int PyMOL_Idle(CPyMOL *I)
{

  int did_work = false;
  PYMOL_API_LOCK

  PyMOLGlobals *G = I->G;
  
  I->DraggedFlag = false;
  if(I->IdleAndReady<IDLE_AND_READY) {
    I->IdleAndReady++;
  }
  if(I->FakeDragFlag==1) {
    I->FakeDragFlag = false;
    OrthoFakeDrag(G);
    did_work = true;
  }

  if(ControlIdling(G)) {
    ExecutiveSculptIterateAll(G);
    did_work = true;
  }

  SceneIdle(G); 

  if(SceneRovingCheckDirty(G)) {
    SceneRovingUpdate(G);
    did_work = true;
  }

  PFlush();
  
#ifndef _PYMOL_NOPY
  if(I->PythonInitStage>0) {
	if(I->PythonInitStage<2) {
	   I->PythonInitStage++;
	} else {
		I->PythonInitStage=-1;
		PBlock();

/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ 
#ifdef _MACPYMOL_XCODE
    /* restore working directory if asked to */
        PRunString("if os.environ.has_key('PYMOL_WD'): os.chdir(os.environ['PYMOL_WD'])");
        PRunString("launch_gui()");
#endif
/* END PROPRIETARY CODE SEGMENT */

		PRunString("adapt_to_hardware()");
		PRunString("exec_deferred()");
		PUnblock();
		PFlush();
	}
  }
#endif

  PYMOL_API_UNLOCK_NO_FLUSH

  return did_work;
}

void PyMOL_ExpireIfIdle(CPyMOL *I)
{
  PYMOL_API_LOCK

  PyMOLGlobals *G = I->G;
  int final_init_done = true;
#ifndef _PYMOL_NOPY
  final_init_done = (I->PythonInitStage==-1);
#endif

  if(!G->HaveGUI) {
    if(final_init_done) {
      if(!OrthoCommandWaiting(G)) {
	if((!G->Option->keep_thread_alive)&&
	   (!G->Option->read_stdin)) {
	  I->ExpireCount++;
	  if(I->ExpireCount==10) {
	    PParse("_quit");
	  }
	}
      }
    }
  }
  PYMOL_API_UNLOCK;
}

void PyMOL_NeedFakeDrag(CPyMOL *I)
{
  I->FakeDragFlag = true;
}

void PyMOL_NeedRedisplay(CPyMOL *I)
{
  I->RedisplayFlag = true;
}

void PyMOL_NeedSwap(CPyMOL *I)
{
  I->SwapFlag = true;
}

void PyMOL_NeedReshape(CPyMOL *I,int mode, int x, int y, int width, int height)
{
  PyMOLGlobals *G = I->G;
  if(width<0) {
    int h;
    BlockGetSize(SceneGetBlock(G),&width,&h);
    if(SettingGetGlobal_b(G,cSetting_internal_gui))
      width+=SettingGetGlobal_i(G,cSetting_internal_gui_width);
  }
  
  /* if height is negative, force a reshape based on the current height */
  
  if(height<0) { 
    int w;
    int internal_feedback;
    BlockGetSize(SceneGetBlock(G),&w,&height);
    internal_feedback = (int)SettingGet(G,cSetting_internal_feedback);
    if(internal_feedback)
      height+=(internal_feedback-1)*cOrthoLineHeight+cOrthoBottomSceneMargin;
    if(SettingGetGlobal_b(G,cSetting_seq_view)&&!SettingGetGlobal_b(G,cSetting_seq_view_overlay))
      height+=SeqGetHeight(G);
  }

  if(G->HaveGUI) {
    I->ReshapeFlag = true;
    I->Reshape[0] = mode;
    I->Reshape[1] = x;
    I->Reshape[2] = y;
    I->Reshape[3] = width;
    I->Reshape[4] = height;
    PyMOL_NeedRedisplay(I);
  } else {
    /* if no gui, then force immediate reshape */
    PyMOLGlobals *G = I->G;
    
    G->Option->winX = width;
    G->Option->winY = height;
    
    OrthoReshape(G,width,height,true);
  }
}

int PyMOL_GetIdleAndReady(CPyMOL *I)
{
	return (I->IdleAndReady==IDLE_AND_READY);
}

int PyMOL_GetReshape(CPyMOL *I)
{
  return I->ReshapeFlag;
}

PyMOLreturn_int_array PyMOL_GetReshapeInfo(CPyMOL *I,int reset)
{
	PyMOLreturn_int_array result = { PyMOLstatus_SUCCESS, PYMOL_RESHAPE_SIZE, NULL };
	if(reset)
		I->ReshapeFlag = false;
	result.array = VLAlloc(int,PYMOL_RESHAPE_SIZE);
	if(!result.array) {
		result.status = PyMOLstatus_FAILURE;
	} else {
		int a;
		for(a=0;a<PYMOL_RESHAPE_SIZE;a++)
			result.array[a] = I->Reshape[a];
	}
	
  return result;
}

void PyMOL_SetPassive(CPyMOL *I,int onOff)
{
  I->PassiveFlag = onOff;
}

void PyMOL_SetClickReady(CPyMOL *I, char *name, int index)
{

  if(name && name[0]) {
    I->ClickReadyFlag = true;
    strcpy(I->ClickedObject,name);
    I->ClickedIndex = index;
  } else {
    I->ClickReadyFlag = false;
  }
}

int PyMOL_GetClickReady(CPyMOL *I, int reset)
{
  int result = I->ClickReadyFlag;
  if(reset) {
    I->ClickReadyFlag = false;
  }
  return result;
}

char *PyMOL_GetClickString(CPyMOL *I,int reset)
{
  char *result = NULL;
  PYMOL_API_LOCK
  int ready = I->ClickReadyFlag;
  if(reset)
    I->ClickReadyFlag = false;
  if(ready) {
    ObjectMolecule *obj = ExecutiveFindObjectMoleculeByName(I->G,I->ClickedObject);
    if(obj && (I->ClickedIndex < obj->NAtom)) {
      AtomInfoType *ai = obj->AtomInfo + I->ClickedIndex;
      result = Alloc(char, OrthoLineLength+1);
      if(result) {
        sprintf(result,
                "type=object:molecule\nobject=%s\nindex=%d\nrank=%d\nid=%d\nsegi=%s\nchain=%s\nresn=%s\nresi=%s\nname=%s\nalt=%s\n",
                I->ClickedObject,
                I->ClickedIndex+1,
                ai->rank,
                ai->id,
                ai->segi,
                ai->chain,
                ai->resn,
                ai->resi,
                ai->name,
                ai->alt);
      }
    }
  }
  PYMOL_API_UNLOCK
  return(result);
}

int PyMOL_FreeResultString(CPyMOL *I,char *st)
{
  PYMOL_API_LOCK
  FreeP(st);
  PYMOL_API_UNLOCK
  return get_status_ok((st!=NULL));
}

int PyMOL_GetRedisplay(CPyMOL *I, int reset)
{
  int result = I->RedisplayFlag;
  
  PYMOL_API_LOCK
  PyMOLGlobals *G = I->G;
  
  if(result) {
    if(SettingGet_b(G,NULL,NULL,cSetting_defer_updates)) {
      result = false;
    } else {
      if(reset)
        I->RedisplayFlag = false;
    }
  }
  PYMOL_API_UNLOCK_NO_FLUSH
  return result;
}

int PyMOL_GetPassive(CPyMOL *I, int reset)
{/* lock intentionally omitted */
  int result = I->PassiveFlag;
  if(reset)
    I->PassiveFlag = false;
  return result;
}

int PyMOL_GetSwap(CPyMOL *I, int reset)
{/* lock intentionally omitted */
  int result = I->SwapFlag;
  if(reset)
    I->SwapFlag = false;
  return result;
}

int PyMOL_GetBusy(CPyMOL *I, int reset)
{/* lock intentionally omitted */
  int result = I->BusyFlag;
  if(reset)
    PyMOL_SetBusy(I,false);
  return result;
}


void PyMOL_SetBusy(CPyMOL *I, int value)
{/* lock intentionally omitted */
  if(!I->BusyFlag) 
    /* if we weren't busy before, then reset the progress indicators */
    PyMOL_ResetProgress(I);

  I->BusyFlag = value;

  if(!I->BusyFlag) /* reset the interrupt flag once we're done being busy */
    PyMOL_SetInterrupt(I,false);
}

int PyMOL_GetInterrupt(CPyMOL *I, int reset)
{ /* lock intentionally omitted */
  int result = I->InterruptFlag;

  if(reset)
    PyMOL_SetInterrupt(I,false);
  
  return result;
}

void PyMOL_SetInterrupt(CPyMOL *I, int value)
{/* lock intentionally omitted */
  I->InterruptFlag = value;
}


void PyMOL_Drag(CPyMOL *I,int x, int y, int modifiers)
{
  PYMOL_API_LOCK
  OrthoDrag(I->G,x,y,modifiers);
  I->DraggedFlag = true;
  PYMOL_API_UNLOCK
}

void PyMOL_Button(CPyMOL *I,int button, int state,int x, int y, int modifiers)
{
  PYMOL_API_LOCK
  OrthoButton(I->G,button,state,x,y,modifiers);
  PYMOL_API_UNLOCK
}

void PyMOL_SetSwapBuffersFn(CPyMOL *I, PyMOLSwapBuffersFn *fn)
{
  I->SwapFn = fn;
}

void PyMOL_SwapBuffers(CPyMOL *I)
{
  if(I->SwapFn && I->G->ValidContext) {
    I->SwapFn();
    I->SwapFlag = false;
  } else {
    I->SwapFlag = true;
  }
}

void PyMOL_RunTest(CPyMOL *I, int group, int test)
{
  PYMOL_API_LOCK
  TestPyMOLRun(I->G, group, test);
  PYMOL_API_UNLOCK
}

void PyMOL_PushValidContext(CPyMOL *I)
{
  if(I && I->G)
    I->G->ValidContext++;
}
void PyMOL_PopValidContext(CPyMOL *I)
{
  if(I && I->G && (I->G->ValidContext>0))
    I->G->ValidContext--;
}

void PyMOL_SetDefaultMouse(CPyMOL *I)
{
  PYMOL_API_LOCK
  PyMOLGlobals *G = I->G;

  ButModeSet(G,0,cButModeRotXYZ);
  ButModeSet(G,1,cButModeTransXY);
  ButModeSet(G,2,cButModeTransZ);
  ButModeSet(G,12,cButModeScaleSlab);
  ButModeSet(G,13,cButModeMoveSlab);
  ButModeSet(G,5,cButModeClipNF);
  ButModeSet(G,14,cButModeMoveSlabAndZoom);
  ButModeSet(G,15,cButModeTransZ);
  ButModeSet(G,20,cButModeCent);
  ButModeSet(G,10,cButModeOrigAt);
  ButModeSet(G,19,cButModeSimpleClick);

  G->Feedback->Mask[FB_Scene] &= ~(FB_Results); /* suppress click messages */
  PYMOL_API_UNLOCK
}