REMARKS  Testing b-factor and occupancy refinements
remarks  

struct 
data_cns_mtf

_cns_mtf.title
; FILENAME="/data/rwgk/test/tmp.mtf"
  FRAGMENT FOR COPROL121 FOR TESTING

  DATE:18-Nov-98  14:17:57       created by user: rwgk
  VERSION:0.4a
;

loop_
_cns_mtf_atom.id
_cns_mtf_atom.segment_id
_cns_mtf_atom.residue_id
_cns_mtf_atom.residue_name
_cns_mtf_atom.atom_name
_cns_mtf_atom.chemical_type
_cns_mtf_atom.charge
_cns_mtf_atom.atom_mass
1 'TEST' '1' 'VAL' 'HT1' 'HC' 0.350000 1.00800
2 'TEST' '1' 'VAL' 'HT2' 'HC' 0.350000 1.00800
3 'TEST' '1' 'VAL' 'N' 'NH3' -0.300000 14.0067
4 'TEST' '1' 'VAL' 'HT3' 'HC' 0.350000 1.00800
5 'TEST' '1' 'VAL' 'CA' 'CH1E' 0.250000 13.0190
6 'TEST' '1' 'VAL' 'CB' 'CH1E' 0.000000E+00 13.0190
7 'TEST' '1' 'VAL' 'CG1' 'CH3E' 0.000000E+00 15.0350
8 'TEST' '1' 'VAL' 'CG2' 'CH3E' 0.000000E+00 15.0350
9 'TEST' '1' 'VAL' 'C' 'C' 0.550000 12.0110
10 'TEST' '1' 'VAL' 'O' 'O' -0.550000 15.9994
11 'TEST' '2' 'LEU' 'N' 'NH1' -0.350000 14.0067
12 'TEST' '2' 'LEU' 'H' 'H' 0.250000 1.00800
13 'TEST' '2' 'LEU' 'CA' 'CH1E' 0.100000 13.0190
14 'TEST' '2' 'LEU' 'CB' 'CH2E' 0.000000E+00 14.0270
15 'TEST' '2' 'LEU' 'CG' 'CH1E' 0.000000E+00 13.0190
16 'TEST' '2' 'LEU' 'CD1' 'CH3E' 0.000000E+00 15.0350
17 'TEST' '2' 'LEU' 'CD2' 'CH3E' 0.000000E+00 15.0350
18 'TEST' '2' 'LEU' 'C' 'C' 0.550000 12.0110
19 'TEST' '2' 'LEU' 'O' 'O' -0.550000 15.9994
20 'TEST' '3' 'SER' 'N' 'NH1' -0.350000 14.0067
21 'TEST' '3' 'SER' 'H' 'H' 0.250000 1.00800
22 'TEST' '3' 'SER' 'CA' 'CH1E' 0.100000 13.0190
23 'TEST' '3' 'SER' 'CB' 'CH2E' 0.250000 14.0270
24 'TEST' '3' 'SER' 'OG' 'OH1' -0.650000 15.9994
25 'TEST' '3' 'SER' 'HG' 'H' 0.400000 1.00800
26 'TEST' '3' 'SER' 'C' 'C' 0.140000 12.0110
27 'TEST' '3' 'SER' 'OT1' 'OC' -0.570000 15.9994
28 'TEST' '3' 'SER' 'OT2' 'OC' -0.570000 15.9994
-1 ' ' ' ' ' ' ' ' ' ' -1.00000 -1.00000

loop_
_cns_mtf_bond.id[1]
_cns_mtf_bond.id[2]
3 5
5 9
9 10
5 6
6 7
6 8
1 3
2 3
4 3
11 13
13 18
18 19
11 12
13 14
14 15
15 16
15 17
9 11
20 22
22 26
20 21
22 23
23 24
24 25
18 20
26 27
26 28
-1 -1

loop_
_cns_mtf_angle.id[1]
_cns_mtf_angle.id[2]
_cns_mtf_angle.id[3]
3 5 9
3 5 6
5 9 10
9 5 6
5 6 7
5 6 8
7 6 8
1 3 2
2 3 4
2 3 5
1 3 4
1 3 5
4 3 5
11 13 18
13 11 12
11 13 14
13 18 19
18 13 14
13 14 15
14 15 16
14 15 17
16 15 17
5 9 11
10 9 11
9 11 13
9 11 12
20 22 26
22 20 21
20 22 23
26 22 23
22 23 24
23 24 25
13 18 20
19 18 20
18 20 22
18 20 21
22 26 27
22 26 28
27 26 28
-1 -1 -1

loop_
_cns_mtf_dihedral.id[1]
_cns_mtf_dihedral.id[2]
_cns_mtf_dihedral.id[3]
_cns_mtf_dihedral.id[4]
3 5 6 7
2 3 5 9
1 3 5 9
4 3 5 9
11 13 14 15
13 14 15 17
9 11 13 18
3 5 9 11
5 9 11 13
20 22 23 24
22 23 24 25
18 20 22 26
11 13 18 20
13 18 20 22
20 22 26 28
-1 -1 -1 -1

loop_
_cns_mtf_improper.id[1]
_cns_mtf_improper.id[2]
_cns_mtf_improper.id[3]
_cns_mtf_improper.id[4]
5 3 9 6
6 8 7 5
13 11 18 14
15 17 16 14
9 5 11 10
11 9 13 12
22 20 26 23
18 13 20 19
20 18 22 21
26 22 28 27
-1 -1 -1 -1

loop_
_cns_mtf_explicit_nonbonded_exclusion.inb
-1

loop_
_cns_mtf_explicit_nonbonded_exclusion.iblo
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1

loop_
_cns_mtf_group_linked_list.first_atom_id
0
5
8
10
13
17
19
22
25
-1

END

param @CNS_TOPPAR:protein.param end
coor 
REMARK FILENAME=""
REMARK - parameter file PARAM19 -
REMARK PEPTIDE GEOMETRY FROM RAMACHANDRAN ET AL BBA 359:298 (1974)
REMARK TORSIONS FROM HAGLER ET AL JACS 98:4600 (1976)
REMARK JORGENSEN NONBOND PARAMETERS JACS 103:3976-3985 WITH 1-4 RC=1.80/0.1
REMARK DATE: 1-APR-87  14:48:04       created by user: KURIYAN
ATOM      1  HT1 VAL     1      -3.950  -0.677  -2.142  1.00  0.00      TEST
ATOM      2  HT2 VAL     1      -4.064   0.998  -1.881  1.00  0.00      TEST
ATOM      3  N   VAL     1      -4.207   0.060  -1.454  1.00 25.01      TEST
ATOM      4  HT3 VAL     1      -5.206  -0.049  -1.186  1.00  0.00      TEST
ATOM      5  CA  VAL     1      -3.353  -0.070  -0.245  1.00 10.21      TEST
ATOM      6  CB  VAL     1      -3.658  -1.409   0.478  1.00 26.78      TEST
ATOM      7  CG1 VAL     1      -3.667  -1.256   2.018  1.00 25.94      TEST
ATOM      8  CG2 VAL     1      -4.972  -2.085   0.140  1.00 28.48      TEST
ATOM      9  C   VAL     1      -1.899   0.093  -0.656  1.00 10.47      TEST
ATOM     10  O   VAL     1      -1.503  -0.499  -1.673  1.00 14.11      TEST
ATOM     11  N   LEU     2      -1.104   0.902   0.074  1.00 17.15      TEST
ATOM     12  H   LEU     2      -1.490   1.500   0.747  1.00  0.00      TEST
ATOM     13  CA  LEU     2       0.340   0.876  -0.150  1.00  9.88      TEST
ATOM     14  CB  LEU     2       1.098   2.086   0.497  1.00 13.33      TEST
ATOM     15  CG  LEU     2       0.790   3.394  -0.296  1.00 13.63      TEST
ATOM     16  CD1 LEU     2      -0.578   3.799  -0.189  1.00 13.95      TEST
ATOM     17  CD2 LEU     2       1.732   4.405   0.290  1.00 14.84      TEST
ATOM     18  C   LEU     2       0.873  -0.476   0.385  1.00  6.06      TEST
ATOM     19  O   LEU     2       0.434  -0.879   1.428  1.00  8.72      TEST
ATOM     20  N   SER     3       1.811  -0.923  -0.413  1.00 13.05      TEST
ATOM     21  H   SER     3       1.940  -0.537  -1.304  1.00  0.00      TEST
ATOM     22  CA  SER     3       2.652  -2.004   0.059  1.00  9.81      TEST
ATOM     23  CB  SER     3       3.463  -2.643  -1.064  1.00 15.39      TEST
ATOM     24  OG  SER     3       4.388  -1.619  -1.668  1.00 16.37      TEST
ATOM     25  HG  SER     3       3.872  -0.891  -2.023  1.00  0.00      TEST
ATOM     26  C   SER     3       3.590  -1.457   1.157  1.00  7.20      TEST
ATOM     27  OT1 SER     3       3.770  -0.296   1.284  1.00 14.37      TEST
END


delete sele ( not known ) end
!
!
do ( store1 = b ) ( all ) !! these B-factors correspond to R-factor of 0.0
do ( store3 = b ) ( all )

! modify the B-factors
do ( b = b * 1.5 ) ( not ( name ca or name c or name o ) ) 
do ( b = b * 0.5 ) ( name ca or name c or name o ) 
show element ( b ) ( not name h* )
!
flags excl * incl xref end 

{* read diffraction data *}
xray
   declare name=fobs type=complex domain=reciprocal end
   declare name=fpart domain=reciprocal type=complex end
   declare name=fcalc domain=reciprocal type=complex end
   declare name=fom domain=reciprocal type=real end
   declare name=weight domain=reciprocal type=real end
   declare name=sigma domain=reciprocal type=real end
   declare name=test domain=reciprocal type=integer end
   
   a=5.0 b=10.0 c=5.0 alpha=90.0 beta=90.0 gamma=90.0
   symmetry=(x,y,z)
   symmetry=(-X,Y+1/2,-Z)
   SCATter ( chemical C* ) 
   2.31000 20.8439 1.02000 10.2075 1.58860 .568700 .865000 51.6512 .215600

   SCATter ( chemical N* )
   12.2126 .005700 3.13220 9.89330 2.01250 28.9975 1.16630 .582600 -11.529

   SCATter ( chemical O* )
   3.04850 13.2771 2.28680 5.70110 1.54630 .323900 .867000 32.9089 .250800

   SCATter ( chemical S* )
   6.90530 1.46790 5.20340 22.2151 1.43790 .253600 1.58630 56.1720 .866900
 
   nreflections=1000  
   reflections 
 INDE  -3   0   0  FOBS= 1.204  180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    1.204 359.970 FPART=    0.000   0.000
 INDE  -2   0   0  FOBS= 28.876 180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=   28.876 179.970 FPART=    0.000   0.000
 INDE  -1   0   0  FOBS= 18.437   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=   18.437 359.970 FPART=    0.000   0.000
 INDE   1   0   0  FOBS= 18.437   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=   18.437 359.970 FPART=    0.000   0.000
 INDE   2   0   0  FOBS= 28.876 180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=   28.876 179.970 FPART=    0.000   0.000
 INDE   3   0   0  FOBS=  1.204 180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    1.204 359.970 FPART=    0.000   0.000
 INDE  -3   1   0  FOBS=  8.071 254.870 FOM=-1.00 WEIGHT= 1.0 FCALC=    8.071 250.450 FPART=    0.000   0.000
 INDE  -2   1   0  FOBS= 16.475 270.750 FOM=-1.00 WEIGHT= 1.0 FCALC=   16.475 265.223 FPART=    0.000   0.000
 INDE  -1   1   0  FOBS= 16.832   3.959 FOM=-1.00 WEIGHT= 1.0 FCALC=   16.832   7.360 FPART=    0.000   0.000
 INDE   1   1   0  FOBS= 16.833 183.959 FOM=-1.00 WEIGHT= 1.0 FCALC=   16.833 187.387 FPART=    0.000   0.000
 INDE   2   1   0  FOBS= 16.478  90.750 FOM=-1.00 WEIGHT= 1.0 FCALC=   16.478  85.221 FPART=    0.000   0.000
 INDE   3   1   0  FOBS=  8.066  74.870 FOM=-1.00 WEIGHT= 1.0 FCALC=    8.066  70.468 FPART=    0.000   0.000
 INDE  -3   2   0  FOBS=  3.765 352.489 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.765   5.590 FPART=    0.000   0.000
 INDE  -2   2   0  FOBS= 12.829 150.719 FOM=-1.00 WEIGHT= 1.0 FCALC=   12.829 146.287 FPART=    0.000   0.000
 INDE  -1   2   0  FOBS=  4.732 262.008 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.732 235.745 FPART=    0.000   0.000
 INDE   0   2   0  FOBS= 91.413 294.823 FOM=-1.00 WEIGHT= 1.0 FCALC=   91.413 295.716 FPART=    0.000   0.000
 INDE   1   2   0  FOBS=  4.732 262.008 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.732 235.745 FPART=    0.000   0.000
 INDE   2   2   0  FOBS= 12.829 150.719 FOM=-1.00 WEIGHT= 1.0 FCALC=   12.829 146.287 FPART=    0.000   0.000
 INDE   3   2   0  FOBS=  3.765 352.489 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.765   5.590 FPART=    0.000   0.000
 INDE  -2   3   0  FOBS=  9.792 246.772 FOM=-1.00 WEIGHT= 1.0 FCALC=    9.792 235.459 FPART=    0.000   0.000
 INDE  -1   3   0  FOBS= 15.988 171.678 FOM=-1.00 WEIGHT= 1.0 FCALC=   15.988 175.160 FPART=    0.000   0.000
 INDE   1   3   0  FOBS= 15.969 351.678 FOM=-1.00 WEIGHT= 1.0 FCALC=   15.969 355.142 FPART=    0.000   0.000
 INDE   2   3   0  FOBS=  9.799  66.772 FOM=-1.00 WEIGHT= 1.0 FCALC=    9.799  55.454 FPART=    0.000   0.000
 INDE  -2   4   0  FOBS=  8.095 117.995 FOM=-1.00 WEIGHT= 1.0 FCALC=    8.095 111.181 FPART=    0.000   0.000
 INDE  -1   4   0  FOBS= 12.838 165.927 FOM=-1.00 WEIGHT= 1.0 FCALC=   12.838 168.365 FPART=    0.000   0.000
 INDE   0   4   0  FOBS=  9.832 230.370 FOM=-1.00 WEIGHT= 1.0 FCALC=    9.832 247.156 FPART=    0.000   0.000
 INDE   1   4   0  FOBS= 12.838 165.927 FOM=-1.00 WEIGHT= 1.0 FCALC=   12.838 168.365 FPART=    0.000   0.000
 INDE   2   4   0  FOBS=  8.095 117.995 FOM=-1.00 WEIGHT= 1.0 FCALC=    8.095 111.181 FPART=    0.000   0.000
 INDE  -2   5   0  FOBS=  5.404 161.671 FOM=-1.00 WEIGHT= 1.0 FCALC=    5.404 152.488 FPART=    0.000   0.000
 INDE  -1   5   0  FOBS=  3.744  77.777 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.744 103.224 FPART=    0.000   0.000
 INDE   1   5   0  FOBS=  3.747 257.777 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.747 283.207 FPART=    0.000   0.000
 INDE   2   5   0  FOBS=  5.405 341.671 FOM=-1.00 WEIGHT= 1.0 FCALC=    5.405 332.490 FPART=    0.000   0.000
 INDE  -1   6   0  FOBS=  4.246 131.815 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.246 155.195 FPART=    0.000   0.000
 INDE   0   6   0  FOBS=  2.777 179.726 FOM=-1.00 WEIGHT= 1.0 FCALC=    2.777 247.821 FPART=    0.000   0.000
 INDE   1   6   0  FOBS=  4.246 131.815 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.246 155.195 FPART=    0.000   0.000
 INDE  -3   0   1  FOBS=  4.649   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.649 359.970 FPART=    0.000   0.000
 INDE  -2   0   1  FOBS=  1.141   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    1.141 359.970 FPART=    0.000   0.000
 INDE  -1   0   1  FOBS= 11.255   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=   11.255 359.970 FPART=    0.000   0.000
 INDE   0   0   1  FOBS= 86.287   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=   86.287 359.970 FPART=    0.000   0.000
 INDE   1   0   1  FOBS= 16.298 180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=   16.298 179.970 FPART=    0.000   0.000
 INDE   2   0   1  FOBS=  9.157 180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    9.157 179.970 FPART=    0.000   0.000
 INDE   3   0   1  FOBS=  6.784 180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.784 179.970 FPART=    0.000   0.000
 INDE  -3   1   1  FOBS=  4.071 270.596 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.071 270.210 FPART=    0.000   0.000
 INDE  -2   1   1  FOBS=  6.493 307.828 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.493 277.777 FPART=    0.000   0.000
 INDE  -1   1   1  FOBS=  6.559  46.882 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.559  34.399 FPART=    0.000   0.000
 INDE   0   1   1  FOBS=  2.951  63.122 FOM=-1.00 WEIGHT= 1.0 FCALC=    2.951  58.758 FPART=    0.000   0.000
 INDE   1   1   1  FOBS= 22.719  70.243 FOM=-1.00 WEIGHT= 1.0 FCALC=   22.719  75.714 FPART=    0.000   0.000
 INDE   2   1   1  FOBS=  1.817 296.681 FOM=-1.00 WEIGHT= 1.0 FCALC=    1.817 357.064 FPART=    0.000   0.000
 INDE   3   1   1  FOBS=  3.134 225.419 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.134 252.496 FPART=    0.000   0.000
 INDE  -3   2   1  FOBS=  5.958 322.520 FOM=-1.00 WEIGHT= 1.0 FCALC=    5.958 324.013 FPART=    0.000   0.000
 INDE  -2   2   1  FOBS= 12.090 247.637 FOM=-1.00 WEIGHT= 1.0 FCALC=   12.090 244.049 FPART=    0.000   0.000
 INDE  -1   2   1  FOBS= 10.724 165.741 FOM=-1.00 WEIGHT= 1.0 FCALC=   10.724 161.056 FPART=    0.000   0.000
 INDE   0   2   1  FOBS= 10.840 295.630 FOM=-1.00 WEIGHT= 1.0 FCALC=   10.840 306.988 FPART=    0.000   0.000
 INDE   1   2   1  FOBS= 14.694  58.885 FOM=-1.00 WEIGHT= 1.0 FCALC=   14.694  69.329 FPART=    0.000   0.000
 INDE   2   2   1  FOBS=  8.962  91.179 FOM=-1.00 WEIGHT= 1.0 FCALC=    8.962  98.076 FPART=    0.000   0.000
 INDE   3   2   1  FOBS=  6.065 104.899 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.065  94.272 FPART=    0.000   0.000
 INDE  -2   3   1  FOBS=  4.147  93.771 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.147  91.481 FPART=    0.000   0.000
 INDE  -1   3   1  FOBS=  4.981 119.372 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.981 129.676 FPART=    0.000   0.000
 INDE   0   3   1  FOBS= 23.202 317.796 FOM=-1.00 WEIGHT= 1.0 FCALC=   23.202 318.582 FPART=    0.000   0.000
 INDE   1   3   1  FOBS= 25.201   9.081 FOM=-1.00 WEIGHT= 1.0 FCALC=   25.201  19.585 FPART=    0.000   0.000
 INDE   2   3   1  FOBS=  3.961 160.825 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.961 135.196 FPART=    0.000   0.000
 INDE  -2   4   1  FOBS=  6.815 166.430 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.815 162.376 FPART=    0.000   0.000
 INDE  -1   4   1  FOBS=  6.801 207.606 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.801 235.632 FPART=    0.000   0.000
 INDE   0   4   1  FOBS=  3.412 138.013 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.412  85.578 FPART=    0.000   0.000
 INDE   1   4   1  FOBS= 10.184 121.528 FOM=-1.00 WEIGHT= 1.0 FCALC=   10.184 125.920 FPART=    0.000   0.000
 INDE   2   4   1  FOBS=  8.646  46.091 FOM=-1.00 WEIGHT= 1.0 FCALC=    8.646  45.478 FPART=    0.000   0.000
 INDE  -1   5   1  FOBS=  4.754 295.285 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.754 291.308 FPART=    0.000   0.000
 INDE   0   5   1  FOBS=  4.226 199.300 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.226 245.587 FPART=    0.000   0.000
 INDE   1   5   1  FOBS=  8.489 327.083 FOM=-1.00 WEIGHT= 1.0 FCALC=    8.489 346.198 FPART=    0.000   0.000
 INDE  -1   6   1  FOBS=  5.863 143.212 FOM=-1.00 WEIGHT= 1.0 FCALC=    5.863 179.336 FPART=    0.000   0.000
 INDE   0   6   1  FOBS=  2.031 168.004 FOM=-1.00 WEIGHT= 1.0 FCALC=    2.031 240.837 FPART=    0.000   0.000
 INDE   1   6   1  FOBS=  2.021  29.207 FOM=-1.00 WEIGHT= 1.0 FCALC=    2.021  35.011 FPART=    0.000   0.000
 INDE  -2   0   2  FOBS=  4.302   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.302 359.970 FPART=    0.000   0.000
 INDE  -1   0   2  FOBS=  6.303 180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.303 179.970 FPART=    0.000   0.000
 INDE   0   0   2  FOBS=  6.944   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.944 359.970 FPART=    0.000   0.000
 INDE   1   0   2  FOBS=  0.078   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    0.078 179.970 FPART=    0.000   0.000
 INDE   2   0   2  FOBS=  4.761   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.761 359.970 FPART=    0.000   0.000
 INDE  -2   1   2  FOBS=  3.810 351.971 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.810 338.726 FPART=    0.000   0.000
 INDE  -1   1   2  FOBS=  4.279 176.911 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.279 221.553 FPART=    0.000   0.000
 INDE   0   1   2  FOBS=  3.077  46.054 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.077  16.942 FPART=    0.000   0.000
 INDE   1   1   2  FOBS= 21.532  49.086 FOM=-1.00 WEIGHT= 1.0 FCALC=   21.532  54.450 FPART=    0.000   0.000
 INDE   2   1   2  FOBS=  7.134 266.096 FOM=-1.00 WEIGHT= 1.0 FCALC=    7.134 258.062 FPART=    0.000   0.000
 INDE  -2   2   2  FOBS=  2.856 250.303 FOM=-1.00 WEIGHT= 1.0 FCALC=    2.856 264.182 FPART=    0.000   0.000
 INDE  -1   2   2  FOBS= 14.597 100.709 FOM=-1.00 WEIGHT= 1.0 FCALC=   14.597  99.949 FPART=    0.000   0.000
 INDE   0   2   2  FOBS=  7.042 105.969 FOM=-1.00 WEIGHT= 1.0 FCALC=    7.042 109.076 FPART=    0.000   0.000
 INDE   1   2   2  FOBS=  0.421  60.147 FOM=-1.00 WEIGHT= 1.0 FCALC=    0.421 148.108 FPART=    0.000   0.000
 INDE   2   2   2  FOBS=  4.378 198.882 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.378 194.834 FPART=    0.000   0.000
 INDE  -2   3   2  FOBS=  1.477  54.226 FOM=-1.00 WEIGHT= 1.0 FCALC=    1.477 105.140 FPART=    0.000   0.000
 INDE  -1   3   2  FOBS=  3.284 236.327 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.284 205.912 FPART=    0.000   0.000
 INDE   0   3   2  FOBS=  9.549 279.789 FOM=-1.00 WEIGHT= 1.0 FCALC=    9.549 288.462 FPART=    0.000   0.000
 INDE   1   3   2  FOBS=  7.598   7.618 FOM=-1.00 WEIGHT= 1.0 FCALC=    7.598  21.080 FPART=    0.000   0.000
 INDE   2   3   2  FOBS=  5.166 178.557 FOM=-1.00 WEIGHT= 1.0 FCALC=    5.166 186.753 FPART=    0.000   0.000
 INDE  -1   4   2  FOBS=  4.172 348.466 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.172 357.490 FPART=    0.000   0.000
 INDE   0   4   2  FOBS=  6.420 123.103 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.420 101.150 FPART=    0.000   0.000
 INDE   1   4   2  FOBS=  7.892 132.394 FOM=-1.00 WEIGHT= 1.0 FCALC=    7.892 142.602 FPART=    0.000   0.000
 INDE   0   5   2  FOBS=  3.160 122.410 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.160 108.399 FPART=    0.000   0.000
 INDE  -1   0   3  FOBS=  8.336   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    8.336 359.970 FPART=    0.000   0.000
 INDE   0   0   3  FOBS= 12.879   0.000 FOM=-1.00 WEIGHT= 1.0 FCALC=   12.879 359.970 FPART=    0.000   0.000
 INDE   1   0   3  FOBS=  0.178 180.000 FOM=-1.00 WEIGHT= 1.0 FCALC=    0.178 179.970 FPART=    0.000   0.000
 INDE  -1   1   3  FOBS=  1.919  79.278 FOM=-1.00 WEIGHT= 1.0 FCALC=    1.919  81.052 FPART=    0.000   0.000
 INDE   0   1   3  FOBS=  6.643 250.716 FOM=-1.00 WEIGHT= 1.0 FCALC=    6.643 256.018 FPART=    0.000   0.000
 INDE   1   1   3  FOBS=  3.182  47.493 FOM=-1.00 WEIGHT= 1.0 FCALC=    3.182  65.574 FPART=    0.000   0.000
 INDE  -1   2   3  FOBS=  4.483 357.004 FOM=-1.00 WEIGHT= 1.0 FCALC=    4.483 323.108 FPART=    0.000   0.000
 INDE   0   2   3  FOBS=  5.826 313.546 FOM=-1.00 WEIGHT= 1.0 FCALC=    5.826 303.393 FPART=    0.000   0.000
 INDE   1   2   3  FOBS=  1.619  75.798 FOM=-1.00 WEIGHT= 1.0 FCALC=    1.619  92.155 FPART=    0.000   0.000
 end
   
  evaluate ($lr=10.)
  evaluate ($hr=3) 
  binresolution $lr $hr 

  tselection=( $hr <= d <= $lr ) 

  mapresolution 2. 
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 


 print target
 wa = 1000.0
   declare name=deri1 type=complex domain=reciprocal end
   declare name=deri2 type=complex domain=reciprocal end
end
!
{* debug B-factor derivatives *}
{* ========================== *}
fix selection=( not ( id 18 or id 19 or id 20 ) ) end 
xray               
 tolerance=0.0
 
  evaluate ($lr=10.)
  evaluate ($hr=2.4) 
  binresolution $lr $hr 
  mapresolution $hr
  tselection=( $hr <= d <= $lr ) 

 method=direct 
 optimize b-factors
  rweight=0.5
  step=0.001 ! step for debugger
  debug=true
 end
 method=fft
 fft grid=0.3 prime=5 avoid=2 end      
 optimize b-factors
  rweight=0.5
  step=0.01  ! step for debugger
  debug=true
 end
end

do (store2=b) (  all )

{* test B-factor cutoffs and dervatives *}

show ( b ) ( ( id 18 or id 19 or id 20 ) )
xray
 method=direct
 optimize bfactors
    bmin=10
    bmax=20
    step=0.000001
    rweight=0
    debug=true
  end
  method=fft
end

do (b=store2) ( all )

{* now run some B-factor refinement *}
fix selection=( not all ) end

xray
  method=direct
  
  evaluate ($lr=10.)
  evaluate ($hr=1.51) 
  binresolution $lr $hr 
  mapresolution $hr
  tselection=( $hr <= d <= $lr ) 

  optimize b-factors
    nstep=20 ! do 20 steps of conjugate gradient
    step_size=10.0  ! expected initial drop in energy 
    tolerance=0.0   ! gradient that terminates minimization
    rweight=-0.2  ! set weight on bfactor restraints by comparing gradient

    ! set the target standard deviations for 1-2 and 1-3 pair B-factors
    ! These are set to be very loose in the test case because 
    ! the Fcalcs are from a structure with loosely restrained B's.
    ! Normally set these to 2.0 or 3.0
    bsigma=( all ) = 7.0
    asigma=( all ) = 8.0
  end
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  print target
end

{* print and compare B-factors *}
show elem ( b )                ( not hydro )
do ( bcomp = store1 - b )      ( all )
show elem ( bcomp )            ( not hydro )

xray
  method=direct
  
  evaluate ($lr=10.)
  evaluate ($hr=1.51) 
  binresolution $lr $hr 
  mapresolution $hr
  tselection=( $hr <= d <= $lr ) 
  
  optimize b-factors
    nstep=20 ! do 20 steps of conjugate gradient
    step_size=10.0  ! expected initial drop in energy 
    tolerance=0.0   ! gradient that terminates minimization
    rweight=0.0  ! no restraints 

    ! set the target standard deviations for 1-2 and 1-3 pair B-factors
    ! These are set to be very loose in the test case because 
    ! the Fcalcs are from a structure with loosely restrained B's.
    ! Normally set these to 2.0 or 3.0
    bsigma=( all ) = 7.0
    asigma=( all ) = 8.0
 end
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  print target
end

do (store9=b) ( all )
do ( b=5. ) ( all )
xray
  optimize b-factors
    nstep=20 ! do 20 steps of conjugate gradient
    step_size=10.0  ! expected initial drop in energy 
    tolerance=0.0   ! gradient that terminates minimization
    rweight=0.0  ! no restraints 
    bmin=4.  
    bmax=6.

    ! set the target standard deviations for 1-2 and 1-3 pair B-factors
    ! These are set to be very loose in the test case because 
    ! the Fcalcs are from a structure with loosely restrained B's.
    ! Normally set these to 2.0 or 3.0
    bsigma=( all ) = 7.0
    asigma=( all ) = 8.0
  end
 end
show element (b ) ( all )
do (b=store9) ( all )

set seed=123 end

do (store9=b) ( all )
do ( b=5. ) ( all )
 do (b=b + gauss(1.5))  
    ( name ca or name n or name c )   
 do (b=b + gauss(2.0))  
    ( not hydrogen and not ( name ca or name n or name c ))
xray
   optimize bfactors nstep=-1  { analysis only: check initial rms B values }
      {* for main-chain atoms *}
      bsigma=( name ca or name n or name c or name o )=1.0
      asigma=( name ca or name n or name c or name o )=1.0 
      {* for side-chain atoms *}
      bsigma=( not( name ca or name n or name c or name o or name hydr ))=1.0 
      asigma=( not( name ca or name n or name c or name o or name hydr ))=1.0 
   end
   display $BRMS_BOND   $BN_BOND   $NGROUP_BOND  $BRMS_BOND_1  $BN_BOND_1   $BRMS_BOND_2  $BN_BOND_2  
   display $NGROUP_ANGL $BRMS_ANGL  $BN_ANGL  $BRMS_ANGL_1 $BN_ANGL_1  $BRMS_ANGL_2  $BN_ANGL_2 
   display $NGROUP_NCS 
end

show ( b ) ( all ) 

xray
  optimize b-factors
    nstep=20 ! do 20 steps of conjugate gradient

    ! set the target standard deviations for 1-2 and 1-3 pair B-factors
    ! These are set to be very loose in the test case because 
    ! the Fcalcs are from a structure with loosely restrained B's.
    ! Normally set these to 2.0 or 3.0
                                      {*Target sigma for 1-2 B-factor pairs*}
                                      {*(for backbone and side chain).     *}
      bsigma=( name ca or name n or name c or name o )=1.5 
      bsigma=( not( name ca or name n or name c or name o ))=2.0 
                                             {*Target sigma for 1-3 (angle)*}
                                             {*B-factor pairs.             *}
      asigma=( name ca or name n or name c or name o )=2.0 
      asigma=( not( name ca or name n or name c or name o ))=2.5 
      
      bmin=-200
      bmax=200
  end
 end
show element (b ) ( all )
do (b=store9) ( all )


{* print and compare B-factors *}
show elem ( b )                ( not hydro )
do ( bcomp = store3 - b )      ( all )
show elem ( bcomp )            ( not hydro )

do ( b = 10.0 ) ( not hydro )
xray
    method=direct 
    predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
    end 
    print target


    {* test isotropic B with K refinement *}
    evaluate ($k2=1.0)
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    
    optimize overall-bfactor
       name=fcalc kscale=true  k=1.0  
       nstep=20  drop=0.4    b=0.0   tolerance=0.0
    end
    target=( resi(amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi(amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall](fobs,fcalc+fpart)) 

    do (deri1=fcalc) ( all )
    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
    end

    {* test anisotropic B with K refinement *}
    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    optimize overall-bfactor  name=fcalc anisotropic=true isotropic=true
       kscale=true  k=1.0    
       nstep=20  drop=0.4    b=0.0   tolerance=0.0
    end
    target=( resi(amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi(amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall](fobs,fcalc+fpart)) 

    do (deri1=fcalc) ( all )
    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end


    {* test isotropic B without K refinement *}
    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    
    optimize overall-bfactor   
       name=fcalc kscale=false  k=1.0  bscale=true 
       nstep=5  drop=0.4    b=0.0   tolerance=0.0
    end

    optimize overall-bfactor  
       method=lbfgs 
       name=fcalc kscale=false  k=1.0  bscale=true 
       nstep=5  drop=0.4    b=0.0   tolerance=0.0
    end

    do (deri1=fcalc) ( all )
    multiscale
      ffk=1
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1     k2=1   
      selection=( 10.0 >= d >= 1.513 )
    end

    {* test anisotropic B without K refinement and without isotropic refinement *}
    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    
    optimize overall-bfactor  name=fcalc anisotropic=true isotropic=false
       kscale=false  k=1.0 bscale=true  
       nstep=4  drop=0.4    b=0.0   tolerance=0.0
    end

    optimize overall-bfactor  name=fcalc anisotropic=true isotropic=false
       method=lbfgs
       kscale=false  k=1.0 bscale=true  
       nstep=4  drop=0.4    b=0.0   tolerance=0.0
    end

    {* test anisotropic B with K refinement and without isotropic refinement *}
    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    
    optimize overall-bfactor  name=fcalc anisotropic=true isotropic=false
       kscale=true  k=1.0 bscale=true   
       nstep=30  drop=0.4    b=0.0   tolerance=0.0
    end
    
    optimize overall-bfactor  name=fcalc anisotropic=true isotropic=false
       kscale=true  k=1.0 bscale=true   
       nstep=30  drop=0.4    b=0.0   tolerance=0.0
       debug=true
    end

    optimize overall-bfactor  name=fcalc anisotropic=true isotropic=false
       method=lbfgs
       kscale=true  k=1.0 bscale=true   
       nstep=30  drop=0.4    b=0.0   tolerance=0.0
    end


    {* test anisotropic B without K refinement *}
    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    optimize overall-bfactor  name=fcalc anisotropic=true isotropic=true
       kscale=false  k=1.0 bscale=true  
       nstep=10  drop=0.4    b=0.0   tolerance=0.0
    end

    do (deri1=fcalc) ( all )
    multiscale
      ffk=$k2
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1    k2=1    
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end

    do (deri1=fcalc) ( all )
    multiscale
      ffk=$k2
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1    k2=1    
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true isotropic=false 
    end
    
    target=( resi(amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi(amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall](fobs,fcalc+fpart)) 
 

    optimize overall-bfactor  
       name=fcalc nstep=0  step=0.0001   b=10.0 debug=true
    end


    optimize overall-bfactor  
       name=fcalc nstep=6  drop=0.4     b=0.0   tolerance=0.0
    end
    print target
    predict 
      mode=reciprocal 
      to=fcalc 
      selection=( $hr <= d <= $lr ) 
      atomselection=( not hydrogen ) 
    end 
    print target
    optimize overall-bfactor  
       name=fcalc nstep=1  drop=0.4    b=0.0   tolerance=0.0
    end                          

    {* test overall anisotropic b-factor optimization *}
    optimize overall-bfactor  anisotropic=true isotropic=true
       name=fcalc debug=true    step=0.0001   
    end


    optimize overall-bfactor  anisotropic=true isotropic=true
       name=fcalc debug=true  b11=2. b22=4. b33=3. b12=4. b13=3. b23=2.
       step=0.0001   
    end

    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    optimize overall-bfactor kscale=true bscale=true anisotropic=true isotropic=true
       name=fcalc debug=true k=.9  b11=2. b22=4. b33=3. b12=4. b13=3. b23=2.
       step=0.0001   
    end
    target=( resi(amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi(amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall](fobs,fcalc+fpart)) 

    optimize overall-bfactor kscale=false bscale=true anisotropic=true isotropic=true
       name=fcalc debug=true k=.9  b11=2. b22=4. b33=3. b12=4. b13=3. b23=2.
       step=0.0001   
    end

    optimize overall-bfactor kscale=false bscale=true anisotropic=true isotropic=false
       name=fcalc debug=true k=.9  b11=2. b22=4. b33=3. b12=4. b13=3. b23=2.
       step=0.0001  
    end

    optimize overall-bfactor kscale=false bscale=true anisotropic=false isotropic=true
       name=fcalc debug=true k=.9  b11=2. b22=4. b33=3. b12=4. b13=3. b23=2.
       step=0.0001  
    end

    optimize overall-bfactor kscale=false bscale=true anisotropic=false isotropic=false
       name=fcalc debug=true k=.9  b11=2. b22=4. b33=3. b12=4. b13=3. b23=2.
       step=0.0001  
    end

    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    optimize overall-bfactor kscale=true bscale=false anisotropic=true isotropic=true
       name=fcalc debug=true k=.9  b11=2. b22=4. b33=3. b12=4. b13=3. b23=2.
       step=0.0001  
    end

    optimize overall-bfactor kscale=true bscale=false anisotropic=true isotropic=false
       name=fcalc debug=true k=.9  b11=2. b22=4. b33=3. b12=4. b13=3. b23=2.
       step=0.0001  
    end

    target=( resi(amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi(amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall](fobs,fcalc+fpart)) 

    do (deri1=fcalc) ( all )
    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true isotropic=false
    end

    do (deri1=fcalc) ( all )
    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end

    do (deri1=$K2*exp(-( $B2_11*h*h*$astar*$astar
                        +$B2_22*k*k*$bstar*$bstar
                        +$B2_33*l*l*$cstar*$cstar
                       +2.0*$B2_12*h*k*$astar*$bstar
                       +2.0*$B2_13*h*l*$astar*$cstar
                       +2.0*$B2_23*k*l*$bstar*$cstar
                      )/4.0)*deri1) ( all )

    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end

    do (deri2=exp(-( 2. *h*h*$astar*$astar
                    +4. *k*k*$bstar*$bstar
                    +2. *l*l*$cstar*$cstar)/4.0)*deri1) ( all )

    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri2        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end

    do (deri1=$K2*exp(-( $B2_11*h*h*$astar*$astar
                        +$B2_22*k*k*$bstar*$bstar
                        +$B2_33*l*l*$cstar*$cstar
                       +2.0*$B2_12*h*k*$astar*$bstar
                       +2.0*$B2_13*h*l*$astar*$cstar
                       +2.0*$B2_23*k*l*$bstar*$cstar
                      )/4.0)*deri2) ( all )

    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end

    optimize overall-bfactor  anisotropic=true isotropic=true
       name=fcalc nstep=8 drop=0.4  tolerance=0.0 
    end

    print target
    optimize overall-bfactor  anisotropic=true isotropic=true
       name=fcalc nstep=1 drop=0.4 tolerance=0.0  
    end


end

do ( b=b+20. ) ( all )

xray
    predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
    end 
    print target
    optimize overall-bfactor  anisotropic=true isotropic=true
       name=fcalc nstep=10 drop=0.04 tolerance=0.0 
    end 
    print target
    predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
    end 
    print target
    optimize overall-bfactor 
       name=fcalc nstep=1 drop=0.4 tolerance=0.0 
    end
end

{* make gaussian distributions, width 1.5 for backbone *}
{* 2.0 for sidechains *}
set seed=314159. end
do ( b = b + gauss(1.5))  ( name ca or name n or name c )
do ( b = b + gauss(2.0))
       ( not hydrogen and not ( name ca or name n or name c ))

xray
   optimize b-factors  nstep=10  end
end

show elem ( b )( not hydro )

! modify the B-factors
do ( b = b + 1.5 ) ( not ( name ca or name c or name o ) ) 
do ( b = b - 0.5 ) ( name ca or name c or name o ) 

do (store9=b) ( all )

{* debug group B-factor and occupancy derivatives *}
{* ============================================== *}
xray               
  evaluate ($lr=10.)
  evaluate ($hr=2.01) 
  binresolution $lr $hr 
  mapresolution $hr
  tselection=( $hr <= d <= $lr ) 
  
 method=fft lookup=true
 optimize group
  drop=0.01 ! step for debugger
  b=( ( name ca or name n or name c ) and resid 1 ) 
  b=( ( name ca or name n or name c ) and resid 2 )
  b=( ( name ca or name n or name c ) and resid 3 ) 
  debug=true
 end
 method=fft lookup=false
 optimize group
  drop=0.00001 ! step for debugger
  b=( ( name ca or name n or name c ) and resid 1 ) 
  b=( ( name ca or name n or name c ) and resid 2 )
  b=( ( name ca or name n or name c ) and resid 3 ) 
  debug=true
 end
 method=direct 
 optimize group
  drop=0.00001 ! step for debugger
  b=( ( name ca or name n or name c ) and resid 1 ) 
  b=( ( name ca or name n or name c ) and resid 2 )
  b=( ( name ca or name n or name c ) and resid 3 ) 
  debug=true
 end
 optimize group 
  drop=10. 
  nstep=8
   b=( not ( hydro or name ca or name c or name o ) ) 
   b=( name ca or name c or name o ) 
   tolerance=0.0
  end
  
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  print target
end

do (b=store9) ( all )

xray  
 optimize group 
  method=lbfgs
  drop=10. 
  nstep=8
   b=( not ( hydro or name ca or name c or name o ) ) 
   b=( name ca or name c or name o ) 
   tolerance=0.0
  end
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  print target

end
do (q=0.8) ( all )
xray      
         
  evaluate ($lr=10.)
  evaluate ($hr=2.01) 
  binresolution $lr $hr 
  mapresolution $hr
  tselection=( $hr <= d <= $lr ) 
  
 method=fft  lookup=true
 optimize group
  drop=0.01 ! step for debugger
  q=( ( name ca or name n or name c ) and resid 1 ) 
  q=( ( name ca or name n or name c ) and resid 2 )
  q=( ( name ca or name n or name c ) and resid 3 ) 
  debug=true
 end
 method=fft  lookup=false
 optimize group
  drop=0.00001 ! step for debugger
  q=( ( name ca or name n or name c ) and resid 1 ) 
  q=( ( name ca or name n or name c ) and resid 2 )
  q=( ( name ca or name n or name c ) and resid 3 ) 
  debug=true
 end
 method=direct 
 optimize group
  drop=0.00001 ! step for debugger
  q=( ( name ca or name n or name c ) and resid 1 ) 
  q=( ( name ca or name n or name c ) and resid 2 )
  q=( ( name ca or name n or name c ) and resid 3 ) 
  debug=true
 end
end
do (q=1.) ( all )
do (q=1. ) ( ( name ca or name n or name c ) and resid 1 )
do (q=1. ) ( ( name ca or name n or name c ) and resid 2 )
do (q=1. ) ( ( name ca or name n or name c ) and resid 3 )
xray
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  do (fobs=combine(amplitude(fcalc),phase(fobs))) ( all ) 
end
do (q=0.5  ) ( ( name ca or name n or name c ) and resid 1 )
do (q=0.7  ) ( ( name ca or name n or name c ) and resid 2 )
do (q=0.8  ) ( ( name ca or name n or name c ) and resid 3 )

do (store8=q) ( all )
xray
 optimize group 
  drop=100. 
  nstep=16
  q=( ( name ca or name n or name c ) and resid 1 ) 
  q=( ( name ca or name n or name c ) and resid 2 )
  q=( ( name ca or name n or name c ) and resid 3 ) 
  end
  
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  print target
end

do (q=store8) ( all )

xray 
 optimize group 
  method=lbfgs
  drop=100. 
  nstep=16
  q=( ( name ca or name n or name c ) and resid 1 ) 
  q=( ( name ca or name n or name c ) and resid 2 )
  q=( ( name ca or name n or name c ) and resid 3 ) 
  end

end
show ( q ) ( name ca ) 
do (q=0.8 ) ( ( name ca or name n or name c ) and resid 1 )
do (b=10. ) ( ( name ca or name n or name c ) and resid 1 )
xray
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
 end 
 do (fobs=combine(amplitude(fcalc),phase(fobs))) ( all )  
end
do (q=1.0 ) ( ( name ca or name n or name c ) and resid 1 )
do (b=12. ) ( ( name ca or name n or name c ) and resid 1 )
xray
 optimize group 
  drop=10. 
  nstep=20
  q=( ( name ca or name n or name c ) and resid 1 ) 
  b=( ( name ca or name n or name c ) and resid 1 )
  end
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  print target
end
show ( q ) ( name ca )
show ( b ) ( name ca ) 

do (q=1.0 ) ( ( name ca or name n or name c ) and resid 1 )
do (b=12. ) ( ( name ca or name n or name c ) and resid 1 )
xray
 optimize group 
 method=lbfgs
  drop=10. 
  nstep=20
  q=( ( name ca or name n or name c ) and resid 1 ) 
  b=( ( name ca or name n or name c ) and resid 1 )
  end
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  print target
end
show ( q ) ( name ca )
show ( b ) ( name ca ) 

do (store8=q) ( all )
do (store9=b) ( all )
do ( q=0.5 ) ( name all )
do ( b=10. ) ( name all ) 
xray
 optimize group 
  drop=10. 
  nstep=20
  bmin=5. bmax=8
  qmin=0.4 qmax=0.74
  q=( ( name ca or name n or name c ) and resid 1 ) 
  b=( ( name ca or name n or name c ) and resid 1 )
  end
  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 
  print target
end

do ( q=0.5 ) ( name all )
do ( b=10. ) ( name all ) 

xray
 optimize group 
  method=lbfgs
  drop=10. 
  nstep=20
  bmin=5. bmax=8
  qmin=0.4 qmax=0.74
  q=( ( name ca or name n or name c ) and resid 1 ) 
  b=( ( name ca or name n or name c ) and resid 1 )
  end

end
show (q) ( ( name ca or name n or name c ) and resid 1 )
show (b) ( ( name ca or name n or name c ) and resid 1 )
do (q=store8) ( all )
do (b=store9) ( all )


xray

  symmetry reset
  
  a=5.0 b=10.0 c=15. alpha=80.0 beta=100.0 gamma=120.0

  evaluate ($lr=10.)
  evaluate ($hr=1.513) 
  binresolution $lr $hr 
  mapresolution $hr
  tselection=( $hr <= d <= $lr ) 

  predict 
     mode=reciprocal 
     to=fcalc 
     selection=( $hr <= d <= $lr ) 
     atomselection=( not hydrogen ) 
  end 

  do (fobs=fcalc+gauss(3.0)) ( all )

  do (deri1=fcalc) ( all )

    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end

    do (deri1=$K2*exp(-( $B2_11*h*h*$astar*$astar
                        +$B2_22*k*k*$bstar*$bstar
                        +$B2_33*l*l*$cstar*$cstar
                       +2.0*$B2_12*h*k*$astar*$bstar
                       +2.0*$B2_13*h*l*$astar*$cstar
                       +2.0*$B2_23*k*l*$bstar*$cstar
                      )/4.0)*deri1) ( all )

    do (deri2=$K2*exp(-( 1.*h*h*$astar*$astar
                        +2.*k*k*$bstar*$bstar
                        +3.*l*l*$cstar*$cstar
                       +2.0*4.*h*k*$astar*$bstar
                       +2.0*5.*h*l*$astar*$cstar
                       +2.0*6.*k*l*$bstar*$cstar
                      )/4.0)*deri1) ( all )

    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri2        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end

    do (deri1=$K2*exp(-( $B2_11*h*h*$astar*$astar
                        +$B2_22*k*k*$bstar*$bstar
                        +$B2_33*l*l*$cstar*$cstar
                       +2.0*$B2_12*h*k*$astar*$bstar
                       +2.0*$B2_13*h*l*$astar*$cstar
                       +2.0*$B2_23*k*l*$bstar*$cstar
                      )/4.0)*deri2) ( all )

    multiscale
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end

    do (fobs=fcalc) ( all ) 
    do (fcalc=2.*exp(-( 1.2*h*h*$astar*$astar
                        +3.2*k*k*$bstar*$bstar
                        +1.2*l*l*$cstar*$cstar
                       +2.0*3.4*h*k*$astar*$bstar
                       +2.0*4.4*h*l*$astar*$cstar
                       +2.0*5.5*k*l*$bstar*$cstar
                      )/4.0)*fcalc) ( all )
                      
    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    do (deri1=fcalc) ( all )
    optimize overall-bfactor kscale=true bscale=true anisotropic=true isotropic=true
       name=fcalc debug=true  
       step=0.0001 
    end

    target=( resi(amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi(amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall](fobs,fcalc+fpart)) 
    optimize overall-bfactor kscale=false bscale=true anisotropic=true isotropic=true
       name=fcalc debug=true  
       step=0.0001 
    end
    optimize overall-bfactor kscale=false bscale=true anisotropic=true isotropic=true
       name=fcalc step=10  
       step=0.0001  nstep=60
    end
    display  0.5 $B2_11 $B2_22  $B2_33 $B2_12 $B2_13 $B2_23
    do (fcalc=0.5 *exp(-( $B_11*h*h*$astar*$astar
                        +$B_22*k*k*$bstar*$bstar
                        +$B_33*l*l*$cstar*$cstar
                       +2.0*$B_12*h*k*$astar*$bstar
                       +2.0*$B_13*h*l*$astar*$cstar
                       +2.0*$B_23*k*l*$bstar*$cstar
                      )/4.0)*fcalc) ( all )

   statistics
      (rvalue(fobs,fcalc+fpart))
      (rvalue[overall](fobs,fcalc+fpart))
      selection=( $hr <= d <= $lr ) 
      output=OUTPUT
   end

    evaluate ($k2=1) 
    target=( resi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    dtarget=( dresi[k=$k2](amplitude(fobs),fcalc+fpart,1)) 
    monitor=( rvalue[overall,k=$k2](fobs,fcalc+fpart)) 
    do (fcalc=deri1) ( all )
    optimize overall-bfactor kscale=true bscale=true anisotropic=true isotropic=true
       name=fcalc step=10 
       step=0.0001  nstep=60 
    end
    do (fcalc=$kscale*exp(-( $B_11*h*h*$astar*$astar
                        +$B_22*k*k*$bstar*$bstar
                        +$B_33*l*l*$cstar*$cstar
                       +2.0*$B_12*h*k*$astar*$bstar
                       +2.0*$B_13*h*l*$astar*$cstar
                       +2.0*$B_23*k*l*$bstar*$cstar
                      )/4.0)*fcalc) ( all )

   statistics
      (rvalue[k=1](fobs,fcalc+fpart))
      (rvalue[k=1,overall](fobs,fcalc+fpart))
      selection=( $hr <= d <= $lr ) 
      output=OUTPUT
   end

    multiscale
      ffk=$k2
      bfmin=-200 bfmax=200.
      set1=fobs  k1=-1 b1=0
      set2=deri1        
      selection=( 10.0 >= d >= 1.513 )
      anisotropic=true
    end
    do (fcalc=$K2*exp(-( $B2_11*h*h*$astar*$astar
                        +$B2_22*k*k*$bstar*$bstar
                        +$B2_33*l*l*$cstar*$cstar
                       +2.0*$B2_12*h*k*$astar*$bstar
                       +2.0*$B2_13*h*l*$astar*$cstar
                       +2.0*$B2_23*k*l*$bstar*$cstar
                      )/4.0)*deri1) ( all )

   statistics
      (rvalue[k=1](fobs,fcalc+fpart))
      (rvalue[k=1,overall](fobs,fcalc+fpart))
      selection=( $hr <= d <= $lr ) 
      output=OUTPUT
   end

   do (fpart=fcalc) ( all ) 

    associate fcalc ( not hydrogen )  
    target= ( resi(amplitude(fobs),fcalc,1)) 
    dtarget(fcalc)=( dresi(amplitude(fobs),fcalc,1)) 
    monitor=( rvalue[overall](fobs,fcalc)) 
    optimize overall-bfactor kscale=false bscale=true anisotropic=true isotropic=true
       name=fcalc step=10  
       step=0.00001  nstep=60
    end
    display  0.5 $B2_11 $B2_22  $B2_33 $B2_12 $B2_13 $B2_23

    associate fpart ( not hydrogen ) 
    target=( resi(amplitude(fobs),fpart,1)) 
    dtarget(fpart)=( dresi(amplitude(fobs),fpart,1)) 
    monitor=( rvalue[overall](fobs,fpart)) 
    optimize overall-bfactor kscale=false bscale=true anisotropic=true isotropic=true
       name=fpart step=10  
       step=0.00001  nstep=60
    end
    display  0.5 $B2_11 $B2_22  $B2_33 $B2_12 $B2_13 $B2_23

end

! test new group feature of "optimize Bfactor"

do (b=20) ( all )
do (q=1) ( all )

xray
    associate reset  
    associate fcalc ( not hydrogen )  
    target= ( resi(amplitude(fobs),fcalc,1)) 
    dtarget(fcalc)=( dresi(amplitude(fobs),fcalc,1)) 
    monitor=( rvalue[overall](fobs,fcalc)) 
    method=direct
    optimize B-factors
      rweight=0
      group=( resid 1 )
      group=( resid 2 )
                                       {*Target sigma for 1-2 B-factor pairs*}
                                      {*(for backbone and side chain).     *}
      bsigma=( name ca or name n or name c or name o )=1.5 
      bsigma=( not( name ca or name n or name c or name o ))=2.0 
                                             {*Target sigma for 1-3 (angle)*}
                                             {*B-factor pairs.             *}
      asigma=( name ca or name n or name c or name o )=2.0 
      asigma=( not( name ca or name n or name c or name o ))=2.5 
      step=0.001
      debug=true
  end
    
     
  optimize b-factors
    nstep=20 ! do 20 steps of conjugate gradient
     group=( resid 1 )
     group=( resid 2 )
 
    ! set the target standard deviations for 1-2 and 1-3 pair B-factors
    ! These are set to be very loose in the test case because 
    ! the Fcalcs are from a structure with loosely restrained B's.
    ! Normally set these to 2.0 or 3.0
                                      {*Target sigma for 1-2 B-factor pairs*}
                                      {*(for backbone and side chain).     *}
      bsigma=( name ca or name n or name c or name o )=1.5 
      bsigma=( not( name ca or name n or name c or name o ))=2.0 
                                             {*Target sigma for 1-3 (angle)*}
                                             {*B-factor pairs.             *}
      asigma=( name ca or name n or name c or name o )=2.0 
      asigma=( not( name ca or name n or name c or name o ))=2.5 
      
      bmin=-200
      bmax=200
  end
 end
show element (b ) ( not hydrogen  )

 xray
   optimize B-factors
      rweight=0
      bmin=10
      bmax=15
      group=( resid 1 )
      group=( resid 2 )
                                       {*Target sigma for 1-2 B-factor pairs*}
                                      {*(for backbone and side chain).     *}
      bsigma=( name ca or name n or name c or name o )=1.5 
      bsigma=( not( name ca or name n or name c or name o ))=2.0 
                                             {*Target sigma for 1-3 (angle)*}
                                             {*B-factor pairs.             *}
      asigma=( name ca or name n or name c or name o )=2.0 
      asigma=( not( name ca or name n or name c or name o ))=2.5 
      step=0.001
      debug=true
 end
 
  optimize b-factors
    nstep=20 ! do 20 steps of conjugate gradient
     group=( resid 1 )
     group=( resid 2 )
      bmin=10
      bmax=15
 
    ! set the target standard deviations for 1-2 and 1-3 pair B-factors
    ! These are set to be very loose in the test case because 
    ! the Fcalcs are from a structure with loosely restrained B's.
    ! Normally set these to 2.0 or 3.0
                                      {*Target sigma for 1-2 B-factor pairs*}
                                      {*(for backbone and side chain).     *}
      bsigma=( name ca or name n or name c or name o )=1.5 
      bsigma=( not( name ca or name n or name c or name o ))=2.0 
                                             {*Target sigma for 1-3 (angle)*}
                                             {*B-factor pairs.             *}
      asigma=( name ca or name n or name c or name o )=2.0 
      asigma=( not( name ca or name n or name c or name o ))=2.5 
      
  end
 end
show element (b ) ( not hydrogen  )

do (b=20) ( all )
do (q=1) ( all )

xray
 optimize b-factors
    nstep=20 ! do 20 steps of lbfgs
    method=lbfgs
    group=( resid 1 )
    group=( resid 2 )

    bmin=-200
    bmax=200
 
    ! set the target standard deviations for 1-2 and 1-3 pair B-factors
    ! These are set to be very loose in the test case because 
    ! the Fcalcs are from a structure with loosely restrained B's.
    ! Normally set these to 2.0 or 3.0
                                      {*Target sigma for 1-2 B-factor pairs*}
                                      {*(for backbone and side chain).     *}
     bsigma=( name ca or name n or name c or name o )=1.5 
     bsigma=( not( name ca or name n or name c or name o ))=2.0 
                                             {*Target sigma for 1-3 (angle)*}
                                             {*B-factor pairs.             *}
     asigma=( name ca or name n or name c or name o )=2.0 
     asigma=( not( name ca or name n or name c or name o ))=2.5 
      
  end
end
 
show element (b ) ( not hydrogen  )

xray
 optimize b-factors
    nstep=20 ! do 20 steps of lbfgs
    method=lbfgs
    group=( resid 1 )
    group=( resid 2 )
     
    bmin=10
    bmax=15
 
    ! set the target standard deviations for 1-2 and 1-3 pair B-factors
    ! These are set to be very loose in the test case because 
    ! the Fcalcs are from a structure with loosely restrained B's.
    ! Normally set these to 2.0 or 3.0
                                      {*Target sigma for 1-2 B-factor pairs*}
                                      {*(for backbone and side chain).     *}
     bsigma=( name ca or name n or name c or name o )=1.5 
     bsigma=( not( name ca or name n or name c or name o ))=2.0 
                                             {*Target sigma for 1-3 (angle)*}
                                             {*B-factor pairs.             *}
     asigma=( name ca or name n or name c or name o )=2.0 
     asigma=( not( name ca or name n or name c or name o ))=2.5 
      
  end
end

show element (b ) ( not hydrogen  )
 
stop