Skip to content

Commit

Permalink
Update README and fix d7dist -- HJB
Browse files Browse the repository at this point in the history
  • Loading branch information
yayahjb committed Jul 7, 2019
1 parent 668d8c8 commit d20f8bd
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 64 deletions.
117 changes: 99 additions & 18 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
ncdist -- Niggli Cone Distance utilities
With S6 and D7 Support
Herbert J. Bernstein and Lawrence C. Andrews
Version 1.0.0 07 Jan 2016
Version 1.1.0 07 Jun 2019

[email protected]


ncdist is a package of two utilities built on the Niggli-Cone cell distance discussed in
[Andrews, L. C., Bernstein, H. J. (2014). "The geometry of Niggli reduction: BGAOL --
embedding Niggli reduction and analysis of boundaries". Journal of applied crystallography,
47(1), 346-359.] which provides a sensitive and reliable metric for the distance between
crystallographic unit cells. A shell command line program ncdist is provided as well as
a shared library rcpp_ncdist (librcpp_ncdist.so) for use of ncdist from R.
embedding Niggli reduction and analysis of boundaries". J. Appl. Cryst.
47(1), 346 -- 359.] which provides a sensitive and reliable metric for the distance between
crystallographic unit cells. Subsequent work has shown that similar distances can be
computed more efficiently based on Selling reduction which is the basis for Delaunay
reduction [Andrews, L. C., Bernstein, H. J. and Sauter, N. K. (2019). "Selling reduction
versus Niggli reduction for crystallographic lattices". Acta Cryst. A75(1), 115 -- 120.]
[Andrews, L. C., Bernstein, H. J. and Sauter, N. K. (2019). "A space for lattice
representation and clustering". Acta Cryst. A75(3), 593 -- 599. Four shell command line
programs, ncdist, d7dist, s6dist_app, and cs6dist_app are provided as well as
a shared libraries, rcpp_ncdist (librcpp_ncdist.so), rcpp_d7dist (librcpp_d7dist.so),
rcpp_s6dist (librcpp_s6dist.so), and rcpp_cs6dist (librcpp_cs6dist.so), for use from R.

The 1.1.0 release of 7 Jun 2019 has been refactored to use code from L. C. Andrews
Lattice Representation Library (https://github.com/duck10/LatticeRepLib.git) with
changes to adapt to the conventions of the ncdist code.

Work on the upgrade to version 1.1.0 has been supported in part by funding from the US
Department of Energy Offices of Biological and Environmental Research and of Basic Energy
Sciences (grant No. DE-AC02-98CH10886 ; grant No. E-SC0012704); U.S. National Institutes
of Health (grant No. P41RR012408; grant No. P41GM103473; grant No. P41GM111244; and grant
No. R01GM117126 ); Dectris, Ltd.

LICENSE

Expand Down Expand Up @@ -61,11 +79,15 @@ LICENSE
# #
######################################################################

THE COMMAND LINE PROGRAM NCDIST
THE COMMAND LINE PROGRAMS NCDIST

The program ncdist accepts two sets of 7 command line arguments:
The programs ncdist, d7dist, s6dist_app and cs6dist_app accept two sets of 7 command
line arguments:

ncdist lat1 a1 b1 c1 alpha1 beta1 gamma1 lat2 a2 b2 c2 alpha2 beta2 gamma2
d7dist lat1 a1 b1 c1 alpha1 beta1 gamma1 lat2 a2 b2 c2 alpha2 beta2 gamma2
s6dist lat1 a1 b1 c1 alpha1 beta1 gamma1 lat2 a2 b2 c2 alpha2 beta2 gamma2
cs6dist lat1 a1 b1 c1 alpha1 beta1 gamma1 lat2 a2 b2 c2 alpha2 beta2 gamma2

lat1 and lat2 are centering symbols
P (Primitive)
Expand All @@ -79,41 +101,100 @@ lat1 and lat2 are centering symbols
a1, b1, c1, a2, b2, c2 are cell edge length in Angstroms
alpha1, beta1, gamma1, alpha2, beta2, gamma2 are cell angles in degrees

A call to
A timed call to ncdist on a 12-core AMD threadripper will produce

ncdist P 100 100 100 90 90 90 P 99 99 99 89 89 89

will produce
time ncdist P 100 100 100 90 90 90 P 99 99 99 89 89 89

Primitive Reduced Probe Cell: 100 100 100 90 90 90
Delaunay Primitive Reduced Probe Cell: 100 100 100 90 90 90
Volume :1e+06
Reciprocal of Primitive Probe Cell: 0.01 0.01 0.01 90 90 90
Volume of Reciprocal Cell: 1e-06
V7 linearized and scaled: 92.582 92.582 92.582 92.582 92.582 92.582 92.582
raw G6 vector: 10000 10000 10000 1.22465e-12 1.22465e-12 1.22465e-12
raw G6 vector: 10000 10000 10000 1.45473e-11 1.45473e-11 1.45473e-11

Primitive Reduced Probe Cell: 99 99 99 89 89 89
Delaunay Primitive Reduced Probe Cell: 99 99 138.78 134.5 90 91
Volume :969861
Reciprocal of Primitive Probe Cell: 0.010104 0.010104 0.010104 90.9828 90.9828 90.9828
Volume of Reciprocal Cell: 1.03108e-06
V7 linearized and scaled: 91.6562 91.6562 91.6562 91.6287 91.6287 91.6287 91.6424
raw G6 vector: 9801 9801 9801 342.102 342.102 342.102

dprim1: [10000, 10000, 10000, 1.22465e-12, 1.22465e-12, 10000]
dprim2: [9801, 9801, 9801, 342.102, 342.102, 9801]
dprim1: [10000, 10000, 10000, 0, 0, 0]
dprim2: [9801, 9801, 9801, 342.102, 342.102, 4.68822e-310]
2.6182

real 0m0.006s
user 0m0.028s
sys 0m0.000s

Similar calls to d7dist, s6dist_app, and cs6dist_app produce

time ./d7dist P 100 100 100 90 90 90 P 99 99 99 89 89 89

dprim1: [10000, 10000, 10000, 30000, 20000, 20000, 20000]
dprim2: [9801, 9801, 19259.9, 19259.9, 9801, 29060.9, 20000]
4.0324

real 0m0.009s
user 0m0.044s
sys 0m0.004s

time ./s6dist_app P 100 100 100 90 90 90 P 99 99 99 89 89 89

dprim1: [0, 0, 0, -10000, -10000, -10000]
dprim2: [-9629.95, -9629.95, 0, -9629.95, -171.051, 0]
rawdist: 663.379
2.57561

real 0m0.005s
user 0m0.000s
sys 0m0.004s

time ./cs6dist_app P 100 100 100 90 90 90 P 99 99 99 89 89 89

Primitive Reduced Probe LRL_Cell: 100 100 100 90 90 90
Delaunay Primitive Reduced Probe LRL_Cell: 100 100 100 90 90 90
Selling Primitive Reduced Probe S6 LRL_Cell: 0 0 0 -10000 -10000 -10000
Volume :1e+06
Reciprocal of Primitive Probe LRL_Cell: 0.0001 0.0001 0.0001 -8.96147e-05 -8.96147e-05 -8.96147e-05
Volume of Reciprocal LRL_Cell: 1e-06
V7 linearized and scaled: 92.582 92.582 92.582 92.582 92.582 92.582 92.582
raw G6 vector for S6: 10000 10000 10000 1.22465e-12 1.22465e-12 1.22465e-12

Primitive Reduced Probe LRL_Cell: 99 99 99 89 89 89
Delaunay Primitive Reduced Probe LRL_Cell: 99 99 138.78 134.5 90 91
Selling Primitive Reduced Probe S6 LRL_Cell: -9629.95 -9629.95 0 -9629.95 -171.051 0
Volume :969861
Reciprocal of Primitive Probe LRL_Cell: 0.000102092 0.000102092 0.000102092 -0.000202632 -0.000202632 -0.000202632
Volume of Reciprocal LRL_Cell: 1.03108e-06
V7 linearized and scaled: 91.6562 91.6562 91.6562 91.6287 91.6287 91.6287 91.6424
raw G6 vector for S6: 19259.9 9801 19259.9 -19259.9 -19259.9 1.68257e-12

dprim1: [0, 0, 0, -10000, -10000, -10000]
dprim2: [-9629.95, -9629.95, 0, -9629.95, -171.051, 0]
rawdist: 663.379
2.57561

real 0m0.018s
user 0m0.280s
sys 0m0.000s


Which says the NCdist distance between these two cells if 2.6182 Angstroms, computed
as 0.1 times the square root of the G6 distance in Angstroms^2. At present the
extra information above the distance is provided to facilitate debugging and will
be made optional in a future version.

THE RCPP INTERFACE TO NCDIST

The library rcpp_ncdist is provided as an interface between R and ncdist. Depending on
the type of system used, the name of the file may be a .dylib, a .dll, a .so and may or may
not be prefixed by lib. Under linux the name is librcpp_ncdist.so. Under OS X the name
is librcpp_ncdist.dylib.
The libraries rcpp_ncdist, rcpp_d7dist, rcpp_s6dist, and rcpp_cs6dist are provided as
an interface between R and ncdist. Depending on the type of system used, the name of
the file may be a .dylib, a .dll, a .so and may or may not be prefixed by lib. Under
linux the names are librcpp_ncdist.so, librcpp_d7dist.so, librcpp_s6dist.so, and
librcpp_cs6dist.so. Under OS X the names are usually librcpp_ncdist.dylib,
librcpp_ncdist.dylib,librcpp_s6dist.dylib, and librcpp_cs6dist.dylib

Assuming the library is named /usr/local/lib/librcpp_ncdist.so , in order to compute
a cell distance in R, the commands are:
Expand Down
98 changes: 58 additions & 40 deletions d7dist.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@


#include "S6M_SellingReduce.h"
#include "D7Dist.h"
#include "G6.h"
#include "D7.h"
#include "S6.h"
#include "LRL_Cell.h"
#include "LRL_Cell_Degrees.h"
#include "Delone.h"
#include "D7Dist.h"
#include "CS6Dist.h"
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <ctype.h>

//*****************************************************************************
G6 makeprimredprobe( std::string testlattice,
double a, double b, double c, double alpha, double beta, double gamma )
D7 makeprimredcell( std::string testlattice,
double a, double b, double c, double alpha, double beta, double gamma )
{
int reduced;
std::string latsym;
char clatsym;
G6 v6cell;
G6 redprimcell;
G6 dredprimcell;
D7 d7redprimcell;
double dredprimcell[7];
double g6primcell[6];
double d7primcell[7];
Mat66 mc;
Mat66 m;
Mat66 dm;
G6 primcell;
G6 recipcell;
G6 reducedBase;
G6 primredprobe;
G6 dprimredprobe;
double d7cell[7];
double d7redcell[7];
double crootvol;
G6 primcell;
LRL_Cell rawcell(a,b,c, alpha,beta,gamma);
int ii;
bool ret;
int reduced;
if (testlattice.size()< 1) {
latsym = "P";
} else {
Expand Down Expand Up @@ -65,35 +60,66 @@ G6 makeprimredprobe( std::string testlattice,
break;
case 'V':
case 'v':
primcell[0] = a;
primcell[1] = b;
primcell[2] = c;
primcell[3] = alpha;
primcell[4] = beta;
primcell[5] = gamma;
primcell[0] = a;
primcell[1] = b;
primcell[2] = c;
primcell[3] = alpha;
primcell[4] = beta;
primcell[5] = gamma;
break;
case 'D':
case 'd':
primcell[0] = a;
primcell[1] = b;
primcell[2] = c;
primcell[3] = beta-b-c;
primcell[4] = gamma-a-c;
primcell[5] = alpha-c-primcell[3]-primcell[4] ;
break;
case 'S':
case 's':
primcell[3] = 2.*a;
primcell[4] = 2.*b;
primcell[5] = 2.*c;
primcell[0] = -alpha-c-b;
primcell[1] = -beta-c-a;
primcell[2] = -gamma-b-a;
break;
default:
std::cerr << "Unrecognized lattice symbol "<< testlattice<<" treated as P" << std::endl;
/* cout << "Unrecognized lattice symbol " << " treated as P", << std::endl; */
latsym = "P";
clatsym = 'P';
clatsym='P';
CS6M_CelltoG6(rawcell,v6cell);
CS6M_LatSymMat66(v6cell,clatsym,mc,primcell);
break;
}
CS6M_G6Reduce(primcell,redprimcell,reduced);
CS6M_G6toD7(primcell,d7cell);
CS6M_D7Reduce(d7cell,d7redcell,reduced);
CS6M_D7toG6(d7redcell,dredprimcell);
return dredprimcell;
reduced=0;
g6primcell[0]=primcell[0];
g6primcell[1]=primcell[1];
g6primcell[2]=primcell[2];
g6primcell[3]=primcell[3];
g6primcell[4]=primcell[4];
g6primcell[5]=primcell[5];
CS6M_G6toD7(g6primcell,d7primcell);
CS6M_D7Reduce(d7primcell,dredprimcell,reduced);
if (reduced) {
d7redprimcell = D7(dredprimcell);
} else {
dredprimcell[0]=dredprimcell[1]=dredprimcell[2]=dredprimcell[3]
=dredprimcell[4]=dredprimcell[5]=dredprimcell[6]=0.;
d7redprimcell = D7(dredprimcell);
}
return d7redprimcell;
}



int main(int argc, char ** argv) {

std::string lat1, lat2;
double a1,b1,c1,alpha1,beta1,gamma1;
double a2,b2,c2,alpha2,beta2,gamma2;
G6 prim1, prim2;
D7 prim1, prim2;
double dprim1[7];
double dprim2[7];
size_t ii;
Expand All @@ -118,20 +144,12 @@ int main(int argc, char ** argv) {
beta2 = atof(argv[13]);
gamma1 = atof(argv[7]);
gamma2 = atof(argv[14]);
prim1 = makeprimredprobe(lat1,a1,b1,c1,alpha1,beta1,gamma1);
prim2 = makeprimredprobe(lat2,a2,b2,c2,alpha2,beta2,gamma2);
for (ii=0; ii < 3; ii++) {
prim1 = makeprimredcell(lat1,a1,b1,c1,alpha1,beta1,gamma1);
prim2 = makeprimredcell(lat2,a2,b2,c2,alpha2,beta2,gamma2);
for (ii=0; ii < 7; ii++) {
dprim1[ii] = prim1[ii];
dprim2[ii] = prim2[ii];
}
dprim1[3] = prim1[0]+prim1[1]+prim1[2]+prim1[3]+prim1[4]+prim1[5];
dprim2[3] = prim2[0]+prim2[1]+prim2[2]+prim2[3]+prim2[4]+prim2[5];
dprim1[4] = +prim1[1]+prim1[2]+prim1[3];
dprim2[4] = +prim2[1]+prim2[2]+prim2[3];
dprim1[5] = prim1[0] +prim1[2] +prim1[4];
dprim2[5] = prim2[0] +prim2[2] +prim2[4];
dprim1[6] = prim1[0]+prim1[1] +prim1[5];
dprim2[6] = prim2[0]+prim2[1] +prim2[5];
std::cout << "dprim1: [" << dprim1[0] <<", "<< dprim1[1] << ", "<< dprim1[2] << ", "
<< dprim1[3] << ", " << dprim1[4] << ", " << dprim1[5] << ", " << dprim1[6]<< "]" << std::endl;
std::cout << "dprim2: [" << dprim2[0] <<", "<< dprim2[1] << ", "<< dprim2[2] << ", "
Expand Down
10 changes: 4 additions & 6 deletions rcpp_ncdist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ G6 makeprimredprobe( std::string testlattice,
primcell[5] = gamma;
break;
default:
Rprintf("Unrecognized lattice symbol %s treated as P\n",testlattice.c_str());
/* Rprintf("Unrecognized lattice symbol %s treated as P\n",testlattice.c_str()) */;
latsym = "P";
mc = rawcell.LatSymMat66(latsym);
primcell = mc*(rawcell.Cell2V6());
Expand All @@ -91,9 +91,9 @@ G6 makeprimredprobe( std::string testlattice,
dprimcell[5]=primcell[5];
CS6M_G6Reduce(dprimcell,dg6redprimcell,reduced);
g6redprimcell = G6(dg6redprimcell);
Rprintf(" dprimcell: [ %g %g %g %g %g %g ]\n", dprimcell[0], dprimcell[1], dprimcell[2], dprimcell[3], dprimcell[4], dprimcell[5]);
Rprintf("dg6redprimcell: [ %g %g %g %g %g %g ]\n", dg6redprimcell[0], dg6redprimcell[1], dg6redprimcell[2],
dg6redprimcell[3], dg6redprimcell[4], dg6redprimcell[5]);
/* Rprintf(" dprimcell: [ %g %g %g %g %g %g ]\n", dprimcell[0], dprimcell[1], dprimcell[2], dprimcell[3], dprimcell[4], dprimcell[5]); */
/* Rprintf("dg6redprimcell: [ %g %g %g %g %g %g ]\n", dg6redprimcell[0], dg6redprimcell[1], dg6redprimcell[2],
dg6redprimcell[3], dg6redprimcell[4], dg6redprimcell[5]); */

return g6redprimcell;
}
Expand Down Expand Up @@ -127,8 +127,6 @@ extern "C" SEXP rcpp_ncdist ( SEXP lat1_, SEXP a1_, SEXP b1_, SEXP c1_,
dprim1[ii] = prim1[ii];
dprim2[ii] = prim2[ii];
}
//std::cout << "dprim1: [" << dprim1[0] <<", "<< dprim1[1] << ", "<< dprim1[2] << ", "<< dprim1[3] << ", " << dprim1[4] << ", " << dprim1[1] <<"]" << std::endl;
//std::cout << "dprim2: [" << dprim2[0] <<", "<< dprim2[1] << ", "<< dprim2[2] << ", "<< dprim2[3] << ", " << dprim2[4] << ", " << dprim2[1] <<"]" << std::endl;
return Rcpp::wrap( 0.1*std::sqrt(NCDist(dprim1,dprim2)));
}

Expand Down

0 comments on commit d20f8bd

Please sign in to comment.