1651 long nxstart, nystart, nzstart;
1652 float xorigin, yorigin, zorigin;
1653 unsigned long count, pnvox;
1654 long nx, ny, nz, mx, my, mz;
1657 float xlen, ylen, zlen, alpha,
beta,
gamma;
1658 long mapc, mapr, maps;
1659 long ispg = 1, nlabl = 0;
1662 float fmax, fmin, fav, fsig;
1663 double dshift, dscale;
1664 char dummychar =
'\0';
1669 float skwmat11 = 1.0f, skwmat12 = 0.0f, skwmat13 = 0.0f, skwmat21 = 0.0f;
1670 float skwmat22 = 1.0f, skwmat23 = 0.0f, skwmat31 = 0.0f, skwmat32 = 0.0f;
1671 float skwmat33 = 1.0f, skwtrn1 = 0.0f, skwtrn2 = 0.0f, skwtrn3 = 0.0f;
1672 char endchar[4] = {1, 1, 0, 0};
1674 fout = fopen(vol_file,
"wb");
1680 pnvox = pextx * pexty * pextz;
1688 if (*((
int *)endchar) > 65536) {
1724 nxstart = (long)
floor((porigx / pwidth) + 0.5);
1725 nystart = (long)
floor((porigy / pwidth) + 0.5);
1726 nzstart = (long)
floor((porigz / pwidth) + 0.5);
1730 if (automode == 0) {
1731 printf(
"lib_vio> Manual override of MRC / CCP4 header fields.\n");
1732 printf(
"lib_vio> \n");
1733 printf(
"lib_vio> The currently assigned data type is 32-bit floats (MODE 2)\n");
1734 printf(
"lib_vio> Select one of the following options: \n");
1735 printf(
"lib_vio> 1: keep MODE 2, 32-bit floats \n");
1736 printf(
"lib_vio> 2: MODE 0, signed 8-bit (range -127...128 as in CCP4), clip any out-of range\n");
1737 printf(
"lib_vio> 3: MODE 0, signed 8-bit (range -127...128 as in CCP4), scale to fit\n");
1738 printf(
"lib_vio> 4: MODE 0, signed 8-bit (range -127...128 as in CCP4), shift and scale to fit\n");
1739 printf(
"lib_vio> 5: MODE 0, unsigned 8-bit (range 0...255 as in old MRC), clip any out-of range\n");
1740 printf(
"lib_vio> 6: MODE 0, unsigned 8-bit (range 0...255 as in old MRC), scale pos., clip neg.\n");
1741 printf(
"lib_vio> 7: MODE 0, unsigned 8-bit (range 0...255 as in old MRC), shift and scale to fit\n");
1742 printf(
"lib_vio> \n");
1743 printf(
"lib_vio> Enter selection number: ");
1745 if (modesel < 1 && modesel > 7) {
1748 printf(
"lib_vio> Did not recognize value, assuming MODE 2, 32-bit floats. \n");
1749 }
else if (modesel > 1) mode = 0;
1751 printf(
"lib_vio> Note: The written data is not affected by changing the following header values.\n");
1752 printf(
"lib_vio> The currently assigned CCP4-style NC field (# columns) is %ld \n", nx);
1753 printf(
"lib_vio> Enter the same or a new value: ");
1755 printf(
"lib_vio> The currently assigned CCP4-style NR field (# rows) is %ld \n", ny);
1756 printf(
"lib_vio> Enter the same or a new value: ");
1758 printf(
"lib_vio> The currently assigned CCP4-style NS field (# sections) is %ld \n", nz);
1759 printf(
"lib_vio> Enter the same or a new value: ");
1761 if (((
unsigned long)nx * (
unsigned long)ny * (
unsigned long)nz) != pnvox) {
1762 printf(
"lib_vio> \n");
1763 fprintf(stderr,
"lib_vio> Warning: NC * NR * NS does not match the total number of voxels in the map.\n");
1764 printf(
"lib_vio> \n");
1766 printf(
"lib_vio> The currently assigned CCP4-style NCSTART field (column start index) is %ld \n", nxstart);
1768 printf(
"lib_vio> Set to zero by default because input grid not in register with origin of coordinate system.\n");
1770 printf(
"lib_vio> Enter the same or a new value: ");
1772 printf(
"lib_vio> The currently assigned CCP4-style NRSTART field (row start index) is %ld \n", nystart);
1774 printf(
"lib_vio> Set to zero by default because input grid not in register with origin of coordinate system.\n");
1776 printf(
"lib_vio> Enter the same or a new value: ");
1778 printf(
"lib_vio> The currently assigned CCP4-style NSSTART field (section start index) is %ld \n", nzstart);
1780 printf(
"lib_vio> Set to zero by default because input grid not in register with origin of coordinate system.\n");
1782 printf(
"lib_vio> Enter the same or a new value: ");
1784 printf(
"lib_vio> The currently assigned MX field (# of X intervals in the unit cell) is %ld \n", mx);
1785 printf(
"lib_vio> Enter the same or a new value: ");
1787 printf(
"lib_vio> The currently assigned MY field (# of Y intervals in the unit cell) is %ld \n", my);
1788 printf(
"lib_vio> Enter the same or a new value: ");
1790 printf(
"lib_vio> The currently assigned MZ field (# of Z intervals in the unit cell) is %ld \n", mz);
1791 printf(
"lib_vio> Enter the same or a new value: ");
1793 printf(
"lib_vio> The currently assigned X unit cell dimension is %f Angstrom\n", xlen);
1794 printf(
"lib_vio> Enter the same or a new value: ");
1796 printf(
"lib_vio> The currently assigned Y unit cell dimension is %f Angstrom\n", ylen);
1797 printf(
"lib_vio> Enter the same or a new value: ");
1799 printf(
"lib_vio> The currently assigned Z unit cell dimension is %f Angstrom\n", zlen);
1800 printf(
"lib_vio> Enter the same or a new value: ");
1802 printf(
"lib_vio> The currently assigned unit cell angle alpha is %f degrees \n", alpha);
1803 printf(
"lib_vio> Enter the same or a new value: ");
1805 printf(
"lib_vio> The currently assigned unit cell angle beta is %f degrees \n", beta);
1806 printf(
"lib_vio> Enter the same or a new value: ");
1808 printf(
"lib_vio> The currently assigned unit cell angle gamma is %f degrees \n", gamma);
1809 printf(
"lib_vio> Enter the same or a new value: ");
1811 printf(
"lib_vio> The currently assigned MAPC field (axis order) is %ld \n", mapc);
1812 printf(
"lib_vio> Enter the same or a new value: ");
1815 if (mapc == 1 || mapc == 2 || mapc == 3) wmaperr = 0;
1820 printf(
"lib_vio> Inconsistent axis order values, assuming mapc = 1, mapr = 2, maps = 3. \n");
1822 printf(
"lib_vio> The currently assigned MAPR field (axis order) is %ld \n", mapr);
1823 printf(
"lib_vio> Enter the same or a new value: ");
1826 if (mapc == 1 && mapr == 2) wmaperr = 0;
1827 if (mapc == 1 && mapr == 3) wmaperr = 0;
1828 if (mapc == 2 && mapr == 1) wmaperr = 0;
1829 if (mapc == 2 && mapr == 3) wmaperr = 0;
1830 if (mapc == 3 && mapr == 1) wmaperr = 0;
1831 if (mapc == 3 && mapr == 2) wmaperr = 0;
1836 printf(
"lib_vio> Inconsistent axis order values, assuming mapc = 1, mapr = 2, maps = 3. \n");
1838 printf(
"lib_vio> The currently assigned MAPS field (axis order) is %ld \n", maps);
1839 printf(
"lib_vio> Enter the same or a new value: ");
1842 if (mapc == 1 && mapr == 2 && maps == 3) wmaperr = 0;
1843 if (mapc == 1 && mapr == 3 && maps == 2) wmaperr = 0;
1844 if (mapc == 2 && mapr == 1 && maps == 3) wmaperr = 0;
1845 if (mapc == 2 && mapr == 3 && maps == 1) wmaperr = 0;
1846 if (mapc == 3 && mapr == 1 && maps == 2) wmaperr = 0;
1847 if (mapc == 3 && mapr == 2 && maps == 1) wmaperr = 0;
1852 printf(
"lib_vio> Inconsistent axis order values, assuming mapc = 1, mapr = 2, maps = 3. \n");
1856 printf(
"lib_vio> The currently assigned MRC2000-style XORIGIN field is %f Angstrom\n", xorigin);
1857 printf(
"lib_vio> Enter the same or a new value: ");
1859 printf(
"lib_vio> The currently assigned MRC2000-style YORIGIN field is %f Angstrom\n", yorigin);
1860 printf(
"lib_vio> Enter the same or a new value: ");
1862 printf(
"lib_vio> The currently assigned MRC2000-style ZORIGIN field is %f Angstrom\n", zorigin);
1863 printf(
"lib_vio> Enter the same or a new value: ");
1872 if (
clipped(pphi, pnvox, 127.0, -128.0))
1873 printf(
"lib_vio> Density values were clipped to fit signed 8-bit data format.\n");
1875 printf(
"lib_vio> Density values already fit signed 8-bit data format, no clipping necessary.\n");
1878 dscale = dmax / 127.0;
1879 if (dmin / -128.0 > dscale)
1880 dscale = dmin / -128.0;
1881 printf(
"lib_vio> Density values will be rescaled to fit signed 8-bit data format.\n");
1882 printf(
"lib_vio> Scaling factor (by which values will be divided): %f .\n", dscale);
1886 dscale = (dmax -
dmin) / 255.0;
1887 dshift = (dmax +
dmin) / 2.0 + 0.5 * dscale;
1888 printf(
"lib_vio> Density values will be centered and rescaled to fit signed 8-bit data format.\n");
1889 printf(
"lib_vio> Center offset value (will be added to map): %f .\n", -dshift);
1890 printf(
"lib_vio> Scaling factor (by which values will be divided): %f .\n", dscale);
1895 if (
clipped(pphi, pnvox, 255.0, 0.0)) printf(
"lib_vio> Density values were clipped to fit unsigned 8-bit data format.\n");
1896 else printf(
"lib_vio> Density values already fit unsigned 8-bit data format, no clipping necessary.\n");
1899 dscale = dmax / 255.0;
1900 printf(
"lib_vio> Density values will be rescaled to fit unsigned 8-bit data format.\n");
1901 printf(
"lib_vio> Scaling factor (by which values will be divided): %f .\n", dscale);
1903 if (
clipped(pphi, pnvox, 256.0, 0.0)) printf(
"lib_vio> Negative density values were clipped to fit unsigned 8-bit data format.\n");
1906 dscale = (dmax -
dmin) / 255.0;
1907 dshift = (dmax +
dmin) / 2.0 - 127.5 * dscale;
1908 printf(
"lib_vio> Density values will be centered and rescaled to fit unsigned 8-bit data format.\n");
1909 printf(
"lib_vio> Center offset value (will be added to map): %f .\n", -dshift);
1910 printf(
"lib_vio> Scaling factor (by which values will be divided): %f .\n", dscale);
1927 printf(
"lib_vio> Converting the unsigned 8-bit (0...255) values to signed (-128...127) for storage (ISO/IEC 10967).\n");
1928 printf(
"lib_vio> The conversion subtracts 256 from density values above 127.\n");
1929 printf(
"lib_vio> Check your software documentation if the `unsigned` convention is supported for MODE 0 maps.\n");
1930 for (count = 0; count < pnvox; count++) if (*(pphi + count) >= 127.5) *(pphi + count) -= 256.0;
1937 printf(
"lib_vio> Writing MRC / CCP4 (binary) volumetric map \n");
1939 if (fwrite(&nx, 4, 1, fout) != 1) wmaperr = 1;
1940 if (fwrite(&ny, 4, 1, fout) != 1) wmaperr = 1;
1941 if (fwrite(&nz, 4, 1, fout) != 1) wmaperr = 1;
1942 if (fwrite(&mode, 4, 1, fout) != 1) wmaperr = 1;
1943 if (fwrite(&nxstart, 4, 1, fout) != 1) wmaperr = 1;
1944 if (fwrite(&nystart, 4, 1, fout) != 1) wmaperr = 1;
1945 if (fwrite(&nzstart, 4, 1, fout) != 1) wmaperr = 1;
1946 if (fwrite(&mx, 4, 1, fout) != 1) wmaperr = 1;
1947 if (fwrite(&my, 4, 1, fout) != 1) wmaperr = 1;
1948 if (fwrite(&mz, 4, 1, fout) != 1) wmaperr = 1;
1949 if (fwrite(&xlen, 4, 1, fout) != 1) wmaperr = 1;
1950 if (fwrite(&ylen, 4, 1, fout) != 1) wmaperr = 1;
1951 if (fwrite(&zlen, 4, 1, fout) != 1) wmaperr = 1;
1952 if (fwrite(&alpha, 4, 1, fout) != 1) wmaperr = 1;
1953 if (fwrite(&beta, 4, 1, fout) != 1) wmaperr = 1;
1954 if (fwrite(&gamma, 4, 1, fout) != 1) wmaperr = 1;
1955 if (fwrite(&mapc, 4, 1, fout) != 1) wmaperr = 1;
1956 if (fwrite(&mapr, 4, 1, fout) != 1) wmaperr = 1;
1957 if (fwrite(&maps, 4, 1, fout) != 1) wmaperr = 1;
1958 if (fwrite(&fmin, 4, 1, fout) != 1) wmaperr = 1;
1959 if (fwrite(&fmax, 4, 1, fout) != 1) wmaperr = 1;
1960 if (fwrite(&fav, 4, 1, fout) != 1) wmaperr = 1;
1961 if (fwrite(&ispg, 4, 1, fout) != 1) wmaperr = 1;
1962 if (fwrite(&dummy, 4, 1, fout) != 1) wmaperr = 1;
1963 if (fwrite(&lskflg, 4, 1, fout) != 1) wmaperr = 1;
1964 if (fwrite(&skwmat11, 4, 1, fout) != 1) wmaperr = 1;
1965 if (fwrite(&skwmat12, 4, 1, fout) != 1) wmaperr = 1;
1966 if (fwrite(&skwmat13, 4, 1, fout) != 1) wmaperr = 1;
1967 if (fwrite(&skwmat21, 4, 1, fout) != 1) wmaperr = 1;
1968 if (fwrite(&skwmat22, 4, 1, fout) != 1) wmaperr = 1;
1969 if (fwrite(&skwmat23, 4, 1, fout) != 1) wmaperr = 1;
1970 if (fwrite(&skwmat31, 4, 1, fout) != 1) wmaperr = 1;
1971 if (fwrite(&skwmat32, 4, 1, fout) != 1) wmaperr = 1;
1972 if (fwrite(&skwmat33, 4, 1, fout) != 1) wmaperr = 1;
1973 if (fwrite(&skwtrn1, 4, 1, fout) != 1) wmaperr = 1;
1974 if (fwrite(&skwtrn2, 4, 1, fout) != 1) wmaperr = 1;
1975 if (fwrite(&skwtrn3, 4, 1, fout) != 1) wmaperr = 1;
1976 for (i = 38; i < 50; ++
i)
if (fwrite(&dummy, 4, 1, fout) != 1) wmaperr = 1;
1977 if (fwrite(&xorigin, 4, 1, fout) != 1) wmaperr = 1;
1978 if (fwrite(&yorigin, 4, 1, fout) != 1) wmaperr = 1;
1979 if (fwrite(&zorigin, 4, 1, fout) != 1) wmaperr = 1;
1980 if (fwrite(mapstring, 4, 1, fout) != 1) wmaperr = 1;
1981 if (fwrite(machstring, 4, 1, fout) != 1) wmaperr = 1;
1982 if (fwrite(&fsig, 4, 1, fout) != 1) wmaperr = 1;
1983 if (fwrite(&nlabl, 4, 1, fout) != 1) wmaperr = 1;
1984 for (i = 0; i < 800; ++
i)
if (fwrite(&dummychar,
sizeof(
char), 1, fout) != 1) wmaperr = 1;
1989 for (count = 0; count < pnvox; count++) {
1990 dummy =
floor(*(pphi + count) + 0.5);
1991 if (dummy < -128 || dummy > 127) wmaperr = 1;
1992 dummychar = (char)dummy;
1993 if (fwrite(&dummychar, 1, 1, fout) != 1) wmaperr = 1;
1997 for (count = 0; count < pnvox; count++) {
1998 dummy = *(pphi + count);
1999 if (fwrite(&dummy, 4, 1, fout) != 1) wmaperr = 1;
2012 printf(
"lib_vio> Volumetric map written to file %s \n", vol_file);
2013 printf(
"lib_vio> Header information: \n");
2014 printf(
"lib_vio> NC = %8ld (# columns)\n", nx);
2015 printf(
"lib_vio> NR = %8ld (# rows)\n", ny);
2016 printf(
"lib_vio> NS = %8ld (# sections)\n", nz);
2017 printf(
"lib_vio> MODE = %8ld (data type: 0: 8-bit char, 2: 32-bit float)\n", mode);
2018 printf(
"lib_vio> NCSTART = %8ld (index of first column, counting from 0)\n", nxstart);
2019 printf(
"lib_vio> NRSTART = %8ld (index of first row, counting from 0)\n", nystart);
2020 printf(
"lib_vio> NSSTART = %8ld (index of first section, counting from 0)\n", nzstart);
2021 printf(
"lib_vio> MX = %8ld (# of X intervals in unit cell)\n", mx);
2022 printf(
"lib_vio> MY = %8ld (# of Y intervals in unit cell)\n", my);
2023 printf(
"lib_vio> MZ = %8ld (# of Z intervals in unit cell)\n", mz);
2024 printf(
"lib_vio> X length = %8.3f (unit cell dimension)\n", xlen);
2025 printf(
"lib_vio> Y length = %8.3f (unit cell dimension)\n", ylen);
2026 printf(
"lib_vio> Z length = %8.3f (unit cell dimension)\n", zlen);
2027 printf(
"lib_vio> Alpha = %8.3f (unit cell angle)\n", alpha);
2028 printf(
"lib_vio> Beta = %8.3f (unit cell angle)\n", beta);
2029 printf(
"lib_vio> Gamma = %8.3f (unit cell angle)\n", gamma);
2030 printf(
"lib_vio> MAPC = %8ld (columns axis: 1=X,2=Y,3=Z)\n", mapc);
2031 printf(
"lib_vio> MAPR = %8ld (rows axis: 1=X,2=Y,3=Z)\n", mapr);
2032 printf(
"lib_vio> MAPS = %8ld (sections axis: 1=X,2=Y,3=Z)\n", maps);
2033 printf(
"lib_vio> DMIN = %8.3f (minimum density value)\n", fmin);
2034 printf(
"lib_vio> DMAX = %8.3f (maximum density value)\n", fmax);
2035 printf(
"lib_vio> DMEAN = %8.3f (mean density value)\n", fav);
2036 printf(
"lib_vio> ISPG = %8ld (space group number)\n", ispg);
2037 printf(
"lib_vio> NSYMBT = %8d (# bytes used for storing symmetry operators)\n", 0);
2038 printf(
"lib_vio> LSKFLG = %8ld (skew matrix flag: 0:none, 1:follows)\n", lskflg);
2040 printf(
"lib_vio> S11 = %8.3f (skew matrix element 11)\n", skwmat11);
2041 printf(
"lib_vio> S12 = %8.3f (skew matrix element 12)\n", skwmat12);
2042 printf(
"lib_vio> S13 = %8.3f (skew matrix element 13)\n", skwmat13);
2043 printf(
"lib_vio> S21 = %8.3f (skew matrix element 21)\n", skwmat21);
2044 printf(
"lib_vio> S22 = %8.3f (skew matrix element 22)\n", skwmat22);
2045 printf(
"lib_vio> S23 = %8.3f (skew matrix element 23)\n", skwmat23);
2046 printf(
"lib_vio> S31 = %8.3f (skew matrix element 31)\n", skwmat31);
2047 printf(
"lib_vio> S32 = %8.3f (skew matrix element 32)\n", skwmat32);
2048 printf(
"lib_vio> S33 = %8.3f (skew matrix element 33)\n", skwmat33);
2049 printf(
"lib_vio> T1 = %8.3f (skew translation element 1)\n", skwtrn1);
2050 printf(
"lib_vio> T2 = %8.3f (skew translation element 2)\n", skwtrn2);
2051 printf(
"lib_vio> T3 = %8.3f (skew translation element 3)\n", skwtrn3);
2053 printf(
"lib_vio> XORIGIN = %8.3f (X origin - MRC2000 only)\n", xorigin);
2054 printf(
"lib_vio> YORIGIN = %8.3f (Y origin - MRC2000 only)\n", yorigin);
2055 printf(
"lib_vio> ZORIGIN = %8.3f (Z origin - MRC2000 only)\n", zorigin);
2056 printf(
"lib_vio> MAP = %c%c%c%c (map string)\n", mapstring[0], mapstring[1], mapstring[2], mapstring[3]);
2057 printf(
"lib_vio> MACHST = %d %d %d %d (machine stamp)\n", machstring[0], machstring[1], machstring[2], machstring[3]);
2058 printf(
"lib_vio> RMS = %8.3f (density rmsd)\n", fsig);
2062 printf(
"lib_vio> Input grid not in register with origin of coordinate system.\n");
2063 printf(
"lib_vio> The origin information was saved only in the MRC2000 format fields.\n");
2064 printf(
"lib_vio> The CCP4 start indexing was set to zero.\n");
2065 printf(
"lib_vio> To invoke a crystallographic CCP4 indexing, you can force an interpolation \n");
2066 printf(
"lib_vio> by converting to an intermediate X-PLOR map using the map2map tool. \n");
int test_registration(float origx, float origy, float origz, float width)
__host__ __device__ float2 floor(const float2 v)
void error_option(int error_number, const char *program)
void error_write_filename(int error_number, const char *program)
double beta(const double a, const double b)
void calc_map_info(double *phi, unsigned long nvox, double *maxdens, double *mindens, double *ave, double *sig)
void error_open_filename(int error_number, const char *program, char *argv)
quaternion_type< T > normalize(quaternion_type< T > q)
void floatshift(double *phi, unsigned long nvox, double dens)
int clipped(double *phi, unsigned long nvox, double max, double min)
fprintf(glob_prnt.io, "\)