float ShakerDoDist(float target, float *v0, float *v1, float *d0to1, float *d1to0, float wt) { float d[3], push[3]; float len, dev, dev_2, sc, result; subtract3f(v0, v1, d); len = (float) length3f(d); dev = target - len; if((result = fabs(dev)) > R_SMALL8) { dev_2 = wt * dev * 0.5F; if(len > R_SMALL8) { /* nonoverlapping */ sc = dev_2 / len; scale3f(d, sc, push); add3f(push, d0to1, d0to1); subtract3f(d1to0, push, d1to0); } else { /* overlapping, so just push in a random direction */ float rd[3]; get_random3f(rd); d0to1[0] -= rd[0] * dev_2; d1to0[0] += rd[0] * dev_2; d0to1[1] -= rd[1] * dev_2; d1to0[1] += rd[1] * dev_2; d0to1[2] -= rd[2] * dev_2; d1to0[2] += rd[2] * dev_2; } } else result = 0.0; return result; }
float ShakerDoPyra(float targ1, float targ2, float *v0, float *v1, float *v2, float *v3, float *p0, float *p1, float *p2, float *p3, float wt, float inv_wt) { float d0[3], cp[3], d2[3], d3[3]; float av[3], t0[3], push[3]; float cur, dev, sc, result1, result2 = 0.0F; add3f(v1, v2, av); subtract3f(v2, v1, d2); add3f(v3, av, av); subtract3f(v3, v1, d3); subtract3f(av, v0, t0); cross_product3f(d2, d3, cp); scale3f(av, 0.33333333F, av); normalize3f(cp); subtract3f(av, v0, d0); cur = dot_product3f(d0, cp); dev = cur - targ1; result1 = (float) fabs(dev); if(result1 > R_SMALL8) { sc = wt * dev; if((cur * targ1) < 0.0) /* inverted */ sc = sc * inv_wt; /* inversion fixing weight */ scale3f(cp, sc, push); add3f(push, p0, p0); scale3f(push, 0.333333F, push); subtract3f(p1, push, p1); subtract3f(p2, push, p2); subtract3f(p3, push, p3); } if((targ2 >= 0.0F) && ((cur * targ1 > 0.0) || (fabs(targ1) < 0.1))) { /* so long as we're not inverted... also make sure v0 is the right distance from the average point */ cur = length3f(d0); normalize3f(d0); dev = cur - targ2; result2 = (float) fabs(dev); if(result2 > R_SMALL4) { sc = wt * dev * 2.0F; scale3f(d0, sc, push); add3f(push, p0, p0); scale3f(push, 0.333333F, push); subtract3f(p1, push, p1); subtract3f(p2, push, p2); subtract3f(p3, push, p3); } } return result1 + result2; }
float ShakerGetPyra(float *targ2, float *v0, float *v1, float *v2, float *v3) { float d0[3], cp[3], d2[3], d3[3]; float av[3], t0[3]; add3f(v1, v2, av); subtract3f(v2, v1, d2); add3f(v3, av, av); subtract3f(v3, v1, d3); subtract3f(av, v0, t0); cross_product3f(d2, d3, cp); scale3f(av, 0.33333333F, av); normalize3f(cp); subtract3f(av, v0, d0); (*targ2) = length3f(d0); return (dot_product3f(d0, cp)); }
float ShakerDoLine(float *v0, float *v1, float *v2, float *p0, float *p1, float *p2, float wt) { /* v0-v1-v2 */ float d0[3], d1[3], cp[3], d2[3], d3[3], d4[3], push[3]; float dev, sc, lcp, result; subtract3f(v2, v1, d2); subtract3f(v0, v1, d1); normalize3f(d2); normalize23f(d1, d0); cross_product3f(d2, d0, cp); lcp = (float) length3f(cp); if(lcp > R_SMALL4) { lcp = 1.0F / lcp; scale3f(cp, lcp, cp); /* axis 0 */ subtract3f(v2, v0, d3); normalize3f(d3); /* axis 1 */ cross_product3f(cp, d3, d4); normalize3f(d4); /* displacement direction */ dev = dot_product3f(d1, d4); /* current deviation */ if((result = (float) fabs(dev)) > R_SMALL8) { sc = wt * dev; scale3f(d4, sc, push); add3f(push, p1, p1); scale3f(push, 0.5F, push); subtract3f(p0, push, p0); subtract3f(p2, push, p2); } else { result = 0.0; } } else result = 0.0; return result; }
float ShakerDoDistLimit(float target, float *v0, float *v1, float *d0to1, float *d1to0, float wt) { float d[3], push[3]; float len, dev, dev_2, sc; if(wt == 0.0F) return 0.0F; subtract3f(v0, v1, d); len = (float) length3f(d); dev = target - len; if(dev < 0.0F) { /* assuming len is non-zero since it is above target */ dev_2 = wt * dev * 0.5F; sc = dev_2 / len; scale3f(d, sc, push); add3f(push, d0to1, d0to1); subtract3f(d1to0, push, d1to0); return -dev; } else return 0.0F; }
static void RepValence(CGO *cgo, bool s1, bool s2, bool isRamped, float *v1, float *v2, int *other, int a1, int a2, float *coord, float *color1, float *color2, int ord, float tube_size, int fancy, unsigned int b1, unsigned int b2, int a, bool b1masked, bool b2masked) { float d[3], t[3], p0[3], p1[3], p2[3]; int a3; const float indent = tube_size; /* direction vector */ subtract3f(v2, v1, p0); copy3f(p0, d); normalize3f(p0); /* need a prioritized third atom to get planarity */ a3 = ObjectMoleculeGetPrioritizedOther(other, a1, a2, NULL); if(a3 < 0) { t[0] = p0[0]; t[1] = p0[1]; t[2] = -p0[2]; } else { subtract3f(coord + 3 * a3, v1, t); normalize3f(t); } cross_product3f(d, t, p1); normalize3f(p1); if(length3f(p1) == 0.0) { p1[0] = p0[1]; p1[1] = p0[2]; p1[2] = p0[0]; cross_product3f(p0, p1, p2); normalize3f(p2); } else { cross_product3f(d, p1, p2); normalize3f(p2); } /* now we have a coordinate system */ mult3f(p2, tube_size, t); bool ord3 = (ord == 3); if (ord3) mult3f(t, 2.f, t); if (fancy || ord3){ RepLine(cgo, s1, s2, isRamped, v1, v2, color1, b1, b2, a, color2, b1masked, b2masked); } if(fancy) { float f[] = { indent, 1.f - indent }; float f_1[] = { 1.f - f[0], 1.f - f[1] }; float vv1[] = { (f_1[0] * v1[0] + f[0] * v2[0]) - 2 * t[0], (f_1[0] * v1[1] + f[0] * v2[1]) - 2 * t[1], (f_1[0] * v1[2] + f[0] * v2[2]) - 2 * t[2] }; float vv2[] = { (f_1[1] * v1[0] + f[1] * v2[0]) - 2 * t[0], (f_1[1] * v1[1] + f[1] * v2[1]) - 2 * t[1], (f_1[1] * v1[2] + f[1] * v2[2]) - 2 * t[2] }; RepLine(cgo, s1, s2, isRamped, vv1, vv2, color1, b1, b2, a, color2, b1masked, b2masked); } else { float vv1[][3] = { { v1[0] - t[0], v1[1] - t[1], v1[2] - t[2] }, { v1[0] + t[0], v1[1] + t[1], v1[2] + t[2] } }; float vv2[][3] = { { v2[0] - t[0], v2[1] - t[1], v2[2] - t[2] }, { v2[0] + t[0], v2[1] + t[1], v2[2] + t[2] } }; RepLine(cgo, s1, s2, isRamped, vv1[0], vv2[0], color1, b1, b2, a, color2, b1masked, b2masked); RepLine(cgo, s1, s2, isRamped, vv1[1], vv2[1], color1, b1, b2, a, color2, b1masked, b2masked); } }
static int RepWireZeroOrderBond(CGO *cgo, bool s1, bool s2, float *v1, float *v2, float *rgb1, float *rgb2, unsigned int b1, unsigned int b2, int a, float dash_gap, float dash_length, bool b1masked, bool b2masked) { int ok = true; float axis[3], naxis[3]; subtract3f(v2, v1, axis); copy3f(axis, naxis); normalize3f(naxis); float blen = length3f(axis); float dash_tot = dash_gap + dash_length; int ndashes = blen / dash_tot; // only do even number of dashes if (ndashes < 2) { ndashes = 2; } else if (ndashes % 2) { --ndashes; } float remspace = blen - (ndashes * dash_length); // remaining space for first gaps float dgap = remspace / (ndashes - 1.f); // endpoints at each vertex, therefore only account for ndashes-1 spaces float placep[3], placep2[3], adddlen[3], adddtot[3]; float dplace; int ndashes_drawn = 0; bool color2_set = false; mult3f(naxis, dash_length, adddlen); // adddlen - length of dash as x/y/z vector mult3f(naxis, dash_length + dgap, adddtot); // adddtot - length of dash plus gap as x/y/z vector copy3f(v1, placep); if (s1){ ok &= CGOColorv(cgo, rgb1); ok &= CGOPickColor(cgo, b1, b1masked ? cPickableNoPick : a); for (dplace = 0.f; (dplace+dash_length) < blen / 2.f; ){ add3f(placep, adddlen, placep2); cgo->add<cgo::draw::line>(placep, placep2); add3f(placep, adddtot, placep); dplace += dash_length + dgap; ++ndashes_drawn; } if (!s2){ if (dplace < blen / 2.f){ // if we are behind the mid-point, only s1, so draw a half-bond add3f(placep, adddlen, placep2); cgo->add<cgo::draw::line>(placep, placep2); add3f(placep, adddtot, placep); dplace += dash_length + dgap; ++ndashes_drawn; } } } else { float tmpp[3]; dplace = (ndashes/2) * (dash_length + dgap); mult3f(naxis, dplace, tmpp); add3f(v1, tmpp, placep); ndashes_drawn = ndashes/2; // if !s1, then definitely s2, so draw half-bond if (dplace <= blen / 2.f){ // if no s1, and we are behind the mid-point, draw half-bond with only s2 add3f(placep, adddlen, placep2); ok &= CGOColorv(cgo, rgb2); ok &= CGOPickColor(cgo, b2, b2masked ? cPickableNoPick : a); color2_set = true; cgo->add<cgo::draw::line>(placep, placep2); add3f(placep, adddtot, placep); dplace += dash_length + dgap; ++ndashes_drawn; } } if (s2){ if (dplace < blen / 2.f){ // if we are behind the mid-point, draw a split cylinder with both colors float tmpp[3]; mult3f(axis, .5f, tmpp); add3f(v1, tmpp, tmpp); cgo->add<cgo::draw::line>(placep, tmpp); add3f(placep, adddlen, placep2); if (!color2_set){ ok &= CGOColorv(cgo, rgb2); ok &= CGOPickColor(cgo, b2, b2masked ? cPickableNoPick : a); } cgo->add<cgo::draw::line>(tmpp, placep2); add3f(placep, adddtot, placep); dplace += dash_length + dgap; ++ndashes_drawn; } else if (!color2_set){ ok &= CGOColorv(cgo, rgb2); ok &= CGOPickColor(cgo, b2, b2masked ? cPickableNoPick : a); } while (ndashes_drawn < ndashes){ add3f(placep, adddlen, placep2); cgo->add<cgo::draw::line>(placep, placep2); add3f(placep, adddtot, placep); dplace += dash_length + dgap; ++ndashes_drawn; } } return ok; }
static void RepAromatic(CGO *cgo, bool s1, bool s2, bool isRamped, float *v1, float *v2, int *other, int a1, int a2, float *coord, float *color1, float *color2, float tube_size, int half_state, unsigned int b1, unsigned int b2, int a, bool b1masked, bool b2masked) { float d[3], t[3], p0[3], p1[3], p2[3], *vv; int a3; int double_sided; /* direction vector */ p0[0] = (v2[0] - v1[0]); p0[1] = (v2[1] - v1[1]); p0[2] = (v2[2] - v1[2]); copy3f(p0, d); normalize3f(p0); /* need a prioritized third atom to get planarity */ a3 = ObjectMoleculeGetPrioritizedOther(other, a1, a2, &double_sided); if(a3 < 0) { t[0] = p0[0]; t[1] = p0[1]; t[2] = -p0[2]; } else { vv = coord + 3 * a3; t[0] = *(vv++) - v1[0]; t[1] = *(vv++) - v1[1]; t[2] = *(vv++) - v1[2]; normalize3f(t); } cross_product3f(d, t, p1); normalize3f(p1); if(length3f(p1) == 0.0) { p1[0] = p0[1]; p1[1] = p0[2]; p1[2] = p0[0]; cross_product3f(p0, p1, p2); normalize3f(p2); } else { cross_product3f(d, p1, p2); normalize3f(p2); } t[0] = p2[0] * tube_size * 2; t[1] = p2[1] * tube_size * 2; t[2] = p2[2] * tube_size * 2; RepLine(cgo, s1, s2, isRamped, v1, v2, color1, b1, b2, a, color2, b1masked, b2masked); if (s1){ CGOColorv(cgo, color1); CGOPickColor(cgo, b1, b1masked ? cPickableNoPick : a); float f[] = { 0.14F, 0.4F } ; float f_1[] = { 1.0F - f[0], 1.0F - f[1] }; float pt1[] = { (f_1[0] * v1[0] + f[0] * v2[0]), (f_1[0] * v1[1] + f[0] * v2[1]), (f_1[0] * v1[2] + f[0] * v2[2]) }; float pt2[] = { (f_1[1] * v1[0] + f[1] * v2[0]), (f_1[1] * v1[1] + f[1] * v2[1]), (f_1[1] * v1[2] + f[1] * v2[2]) }; float p1[3], p2[3]; subtract3f(pt1, t, p1); subtract3f(pt2, t, p2); cgo->add<cgo::draw::line>(p1, p2); if(double_sided) { add3f(pt1, t, p1); add3f(pt2, t, p2); cgo->add<cgo::draw::line>(p1, p2); } } if (s2){ CGOColorv(cgo, color2); CGOPickColor(cgo, b2, b2masked ? cPickableNoPick : a); float f[] = { 0.6F, 0.86F } ; float f_1[] = { 1.0F - f[0], 1.0F - f[1] }; float pt1[] = { (f_1[0] * v1[0] + f[0] * v2[0]), (f_1[0] * v1[1] + f[0] * v2[1]), (f_1[0] * v1[2] + f[0] * v2[2]) }; float pt2[] = { (f_1[1] * v1[0] + f[1] * v2[0]), (f_1[1] * v1[1] + f[1] * v2[1]), (f_1[1] * v1[2] + f[1] * v2[2]) }; float p1[3], p2[3]; subtract3f(pt1, t, p1); subtract3f(pt2, t, p2); cgo->add<cgo::draw::line>(p1, p2); if(double_sided) { add3f(pt1, t, p1); add3f(pt2, t, p2); cgo->add<cgo::draw::line>(p1, p2); } } }
float ShakerDoPlan(float *v0, float *v1, float *v2, float *v3, float *p0, float *p1, float *p2, float *p3, float target, int fixed, float wt) { float result; float d01[3], d12[3], d23[3], d03[3], cp0[3], cp1[3], dp, sc, dev, d0[3], push[3]; double s01, s12, s23, s03; subtract3f(v0, v1, d01); subtract3f(v1, v2, d12); subtract3f(v2, v3, d23); subtract3f(v0, v3, d03); s03 = lengthsq3f(d03); s01 = lengthsq3f(d01); s12 = lengthsq3f(d12); s23 = lengthsq3f(d23); if((s03 < s01) || (s03 < s12) || (s03 < s23)) return 0.0F; cross_product3f(d01, d12, cp0); cross_product3f(d12, d23, cp1); normalize3f(cp0); normalize3f(cp1); dp = dot_product3f(cp0, cp1); result = (dev = 1.0F - (float) fabs(dp)); if(dev > R_SMALL4) { /* add3f(cp0,cp1,d0); normalize3f(d0); cross_product3f(cp0,d12,pos); dp2 = dot_product3f(cp1,pos); */ if(fixed && (dp * target < 0.0F)) { /* fixed & backwards... */ if(dp < 0.0F) { sc = -wt * dev * 0.5F; } else { sc = wt * dev * 0.5F; } sc *= 0.02F; /* weaken considerably to allow resolution of inconsistencies (folded rings, etc.) */ } else if(dp > 0) { sc = -wt * dev * 0.5F; } else { sc = wt * dev * 0.5F; } if(fixed && (fixed < 7)) { /* in small rings, ramp up the planarity factor */ sc *= 8; } else { sc *= 0.2F; } /* pair-wise nudges */ subtract3f(v0, v3, d0); normalize3f(d0); scale3f(d0, sc, push); add3f(push, p0, p0); subtract3f(p3, push, p3); subtract3f(v1, v2, d0); normalize3f(d0); scale3f(d0, sc, push); add3f(push, p1, p1); subtract3f(p2, push, p2); sc = -sc; subtract3f(v0, v2, d0); normalize3f(d0); scale3f(d0, sc, push); add3f(push, p0, p0); subtract3f(p2, push, p2); subtract3f(v1, v3, d0); normalize3f(d0); scale3f(d0, sc, push); add3f(push, p1, p1); subtract3f(p3, push, p3); } else { result = 0.0; } return result; }