%void
%coeff_initializer( FArray2D_double & coeff )
% {
%#h.r.d.10 (helix distance)
coeff(1,1) = -20897.2963242561;
coeff(2,1) = 64247.6438427233;
coeff(3,1) = -83351.2088271679;
coeff(4,1) = 59275.3348525644;
coeff(5,1) = -24993.0213101615;
coeff(6,1) = 6256.27794663695;
coeff(7,1) = -861.843894662537;
coeff(8,1) = 50.4501160458263;
%#e.r.d.10 (sheet distance)
coeff(1,2) = -20548.3707305135;
coeff(2,2) = 65573.1420852652;
coeff(3,2) = -88281.0899077548;
coeff(4,2) = 65135.8946527841;
coeff(5,2) = -28487.2557887243;
coeff(6,2) = 7394.5552104088;
coeff(7,2) = -1055.95001101041;
coeff(8,2) = 64.0502420663362;
%#sp2.r.d.10 (sp2 sc-scdistance)  better fit if only take dist > 1.5...
coeff(1,3) = -118.7061916934;
coeff(2,3) = -597.8637658297;
coeff(3,3) = 2451.48848438076;
coeff(4,3) = -3206.52242150112;
coeff(5,3) = 2076.238123411;
coeff(6,3) = -726.253809304122;
coeff(7,3) = 131.77771968571;
coeff(8,3) = -9.75390463958964;
%#sp3.r.d.10 (sp3 sc-sc distance)
coeff(1,4) = 375.677536653158;
coeff(2,4) = -2831.19317546727;
coeff(3,4) = 6348.51127644845;
coeff(4,4) = -6736.85542456485;
coeff(5,4) = 3904.1482667666;
coeff(6,4) = -1273.43383361067;
coeff(7,4) = 220.113790001637;
coeff(8,4) = -15.7173625861269;
%#h.xD.d.10 (helix xD angle)
coeff(1,5) = 13.1761011064371;
coeff(2,5) = 6.67268543875679;
coeff(3,5) = -294.055688032283;
coeff(4,5) = 1866.10364337877;
coeff(5,5) = -5355.8036552271;
coeff(6,5) = 7923.03899964551;
coeff(7,5) = -5888.11906511642;
coeff(8,5) = 1736.97818014834;
%#e.xD.d.10 (sheet xD angle)
coeff(1,6) = 13.127927303063;
coeff(2,6) = 0.822868665987038;
coeff(3,6) = -109.910665370086;
coeff(4,6) = 686.786517638211;
coeff(5,6) = -1942.11269671157;
coeff(6,6) = 2836.84871202931;
coeff(7,6) = -2095.85402633764;
coeff(8,6) = 617.160098870171;
%#sp2.xD.s.d.10 (sp2 xD angle short range (<2.1 AA))
coeff(1,7) = 12.3002419354918;
coeff(2,7) = -4.7448972963389;
coeff(3,7) = -3.57500757688594;
%#sp2.xD.l.d.100 (sp2 xD angle long range (>2.1 AA))
coeff(1,8) = 6.57363492607565;
coeff(2,8) = -4.23172288336822;
coeff(3,8) = 1.58016437009784;
%#sp3.xD.s.d.10 (sp3 xD angle short range (<2.1 AA))
coeff(1,9) = 12.2116835353074;
coeff(2,9) = -7.16425671041666;
coeff(3,9) = -0.629799940391145;
%#sp3.xD.l.d.10 (sp3 xD angle longrange (>2.1 AA))
coeff(1,10) = 6.78743191739409;
coeff(2,10) = -3.2345923209685;
coeff(3,10) = 1.39326898971812;
%#h.xH.d.100 ()
coeff(1,11) = 11.9350231894526;
coeff(2,11) = 18.409859118441;
coeff(3,11) = -241.176866650372;
coeff(4,11) = 1135.03014758504;
coeff(5,11) = -2716.19210529742;
coeff(6,11) = 3463.22973054283;
coeff(7,11) = -2303.26203622031;
coeff(8,11) = 641.36914663319;
%#e.xH.d.100 ()
coeff(1,12) = 11.5196524630225;
coeff(2,12) = -0.982514077302885;
coeff(3,12) = -38.7140999410775;
coeff(4,12) = 204.61420850299;
coeff(5,12) = -573.17550726292;
coeff(6,12) = 837.762308008926;
coeff(7,12) = -624.832463761649;
coeff(8,12) = 190.175068834576;
%#sp2.xH.s.d.100 (sp2 xH angle shortrange (<2.1 AA))
coeff(1,13) = 7.48291779029918;
coeff(2,13) = -11.4461758882338;
coeff(3,13) = 10.6177843320035;
%#sp2.xH.l.d.100 (sp2 xH angle long range (>2.1 AA))
coeff(1,14) = 4.76014765119106;
coeff(2,14) = -2.74345435413267;
coeff(3,14) = 2.71214471299479;
%#sp3.xH.d.10 (sp3 xH angle all)
coeff(1,15) = 5.08527774066672;
coeff(2,15) = -6.87443803002661;
coeff(3,15) = 6.45151885957664;
%#ring.xP.d.10 (ring N xH acceptor all)
coeff(1,16) = 2.582609;
coeff(2,16) = -27.898499;
coeff(3,16) = 184.031158;
coeff(4,16) = -497.581482;
coeff(5,16) = 490.462250;
coeff(6,16) = 74.764015;
coeff(7,16) = -412.507416;
coeff(8,16) = 184.580704;
%	}

%	void
%	offset_initializer( FArray1D_double & offset )
%	{
offset(1) = 9.939481771384827;
offset(2) = 10.19618640787044;
offset(3) = 5.336869192943302;
offset(4) = 5.160319354819371;
offset(5) = 13.21710000037653;
offset(6) = 13.12950318803366;
offset(7) = 12.30024147033691;
offset(8) = 6.573635101318359;
offset(9) = 12.21168327331543;
offset(10) = 6.787431716918945;
offset(11) = 11.93502330780029;
offset(12) = 11.51965236663818;
offset(13) = 7.482917785644531;
offset(14) = 4.760147571563721;
offset(15) = 5.085277557373047;
offset(16) = -0.5667;
%	}

%	void
%	scale_initializer( FArray1D_double & scale )
%	{
scale(1) = 1.949735682035433;
scale(2) = 2.356555305029287;
scale(3) = 1.042771813719776;
scale(4) = .7320532810196339;
scale(5) = 6.087614983434979;
scale(6) = 6.267133357753898;
scale(7) = 8.319905042648315;
scale(8) = 8.319905042648315; % long range on same scale as short
% scale(8) = 2.651558518409729;
scale(9) = 7.794056534767151;
scale(10) = 7.794056534767151;
% scale(10) = 1.841323494911194;
scale(11) = 5.859906135778155;
scale(12) = 5.590825514968365;
scale (13) = 3.084799265279046;
scale (14) = 3.084799265279046;
% scale (14) = 0.6937812965480070;
scale (15) = 1.831269767104503;
scale (16) = 1.000000000000000;
%	}

		maxr(1) = 2.800000; % distance cut-offs
		maxr(2) = 2.745000;
		maxr(3) = 2.5000;
		maxr(4) = 2.4500000;
		maxr(5) = 2.500000;

        
figure(1)
clf
col = ['r','g','b','k'];
plot([1.4 max(maxr)], [0 0], 'y'); hold on
for i = 1:4
x = [1.4:0.01:maxr(i)-0.005 maxr(i)]; % distance based polynomials are 1-4
y = (polyval(flipud(coeff(:,i)), x)-offset(i))/(2*scale(i));
y(y>0) = 0;
%plot([maxr(i) maxr(i)], [min(y) max(y)], 'y');
plot(x,y, col(i));
end

figure(2)
clf
col = ['r','g','b','c','k','m'];
x = [0:.01:.89 .9:.001:.999 1];
plot(180-rad2deg(acos([min(x) max(x)])), [0 0], 'y'); hold on
for i = 5:10
y = (polyval(flipud(coeff(:,i)), x)-offset(i))/(2*scale(i));
y(y>0) = 0;
plot(180-rad2deg(acos(x)), y, col(i-4));
end

figure(3)
clf
col = ['r','g','b','c','k','m'];
x = [0:.01:.89 .9:.001:.999 1]
plot(180-rad2deg(acos([min(x) max(x)])), [0 0], 'y'); hold on
for i = 11:16
y = (polyval(flipud(coeff(:,i)), x)-offset(i))/(2*scale(i));
y(y>0) = 0;
plot(180-rad2deg(acos(x)), y, col(i-10));
end
