Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* Remove case sensitivity of xyz file inputs (#9)
* Add CLI option to disable centering of molecules (#14)
* Disable default rotation wrt inertia axis for z-matrix input and add a CLI option to force it (#14)
* Read molecules from the standard input
* Show infrared intensities and mode masses
* Read molecules from the standard input (#28)
* Show infrared intensities and mode masses (#35)
* Improve the text-in-corner look (de242c7, #36)
* Improve data structures and code readability

### Fixes
Expand All @@ -24,6 +25,7 @@
* Fix NaNs when compute dihedrals (#14)
* Fix the "readagain" (`r`) and "readmore" (`tab`) bugs (#31)
* Fix z-matrix input with unit=bohr (8554864)
* Fix text blinking when playing animation (80cae88, #36)

### Coming in the next version:
* extended xyz (#16, #17)
Expand Down
2 changes: 1 addition & 1 deletion obj/v/ac3_print.d
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
obj/v/ac3_print.o obj-pic/v/ac3_print.o: src/v/ac3_print.c src/v/v.h \
src/mol/mol.h src/mol/common.h src/v/pars.h
src/mol/mol.h src/mol/common.h src/v/pars.h src/math/vec3.h
2 changes: 1 addition & 1 deletion obj/v/evr.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
obj/v/evr.o obj-pic/v/evr.o: src/v/evr.c src/v/v.h src/mol/mol.h \
src/mol/common.h src/v/pars.h src/v/x.h src/v/evr.h src/math/3d.h \
src/mol/common.h src/v/pars.h src/v/evr.h src/math/3d.h \
src/math/matrix.h src/math/vecn.h src/math/vec3.h
3 changes: 3 additions & 0 deletions obj/v/redraw.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
obj/v/redraw.o obj-pic/v/redraw.o: src/v/redraw.c src/v/v.h src/mol/mol.h \
src/mol/common.h src/v/pars.h src/v/evr.h src/math/3d.h \
src/math/matrix.h src/math/vecn.h
4 changes: 2 additions & 2 deletions obj/v/x.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
obj/v/x.o obj-pic/v/x.o: src/v/x.c src/v/v.h src/mol/mol.h \
src/mol/common.h src/v/pars.h src/v/x.h src/math/vec2.h \
src/mol/palette_v.h src/mol/palette_cpk.h
src/mol/common.h src/v/pars.h src/v/x.h src/mol/palette_v.h \
src/mol/palette_cpk.h
8 changes: 3 additions & 5 deletions python/vmol/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class vibr_t(ctypes.Structure): # noqa: N801
double * ints;
double * disp;
double * mass;
double * r0;
int n;
} vibr_t;
```
Expand All @@ -58,7 +57,6 @@ class vibr_t(ctypes.Structure): # noqa: N801
("ints", c_double_p),
("disp", c_double_p),
("mass", c_double_p),
("r0", c_double_p),
("n", c_int),
)

Expand Down Expand Up @@ -399,13 +397,13 @@ def vib2struct(nat, vib=None):

Returns:
vibr_t: An instance of `vibr_t` with the fields set. If missing, the optional fields are set to 0,
and the `r0` is set to NULL. If the input dictionary is None, everything is set to 0/NULL.
If the input dictionary is None, everything is set to 0/NULL.

Raises:
TypeError: If mol is neither a dictionary nor None.
"""
if vib is None:
return vibr_t(n=c_int(0), disp=None, freq=None, ints=None, mass=None, r0=None)
return vibr_t(n=c_int(0), disp=None, freq=None, ints=None, mass=None)

if not isinstance(vib, dict):
msg = f"vib must be None or a dictionary, but got {type(vib)}"
Expand Down Expand Up @@ -452,7 +450,7 @@ def check_array(key, required=True, shape=None, ndim=None, dtype=c_double):
for key, val in vdict.items():
vdict[key] = val.ctypes.data_as(c_double_p)

v = vibr_t(n=nvib, disp=vdict['disp'], freq=vdict['freq'], ints=vdict['ints'], mass=vdict['mass'], r0=None)
v = vibr_t(n=nvib, disp=vdict['disp'], freq=vdict['freq'], ints=vdict['ints'], mass=vdict['mass'])
v._keepalive = (nvib, vdict['disp'], vdict['freq'], vdict['ints'], vdict['mass']) # keep strong references
return v

Expand Down
6 changes: 4 additions & 2 deletions src/math/3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

#define DEG2RAD (M_PI/180.0)

void rotmx0_update(double mx[9], double mx1[9], double phi, int axis);
void rot3d (int n, double * r, double m[9]);
void rotmx0_update(double mx[9], double phi, int axis);
void rot3d(int n, double * v, const double * r, const double m[9]);
void rot3d_inplace(int n, double * r, const double m[9]);
void rotmx (double * rot, double * u, double phi);
void rot_around_perp(double rot[9], double dx, double dy, double factor);
void mx3_lmultmx(const double A[9], double B[9]);

int zmat2cart(int n, double r[3],
double a[3], double b[3], double c[3],
Expand Down
2 changes: 1 addition & 1 deletion src/math/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void mx_id(unsigned int n, double * a){
}

void mx_multmx(unsigned int m, unsigned int n, unsigned int q,
double * p, double * a, double * b){
double * p, const double * a, const double * b){
/* a: m*n
* b: n*q
* p = ab: m*q
Expand Down
2 changes: 1 addition & 1 deletion src/math/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static inline unsigned int mpos(unsigned int i, unsigned int j){
#endif

void mx_id (unsigned int n, double * a);
void mx_multmx (unsigned int m, unsigned int n, unsigned int q, double * p, double * a, double * b);
void mx_multmx (unsigned int m, unsigned int n, unsigned int q, double * p, const double * a, const double * b);
int mx_inv (unsigned int n, unsigned int r, double * b, double * a, double eps);
void jacobi (double * a, double * b, double * d, unsigned int n, double eps, unsigned int rot, FILE * f);

24 changes: 17 additions & 7 deletions src/math/rot3d.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#include "3d.h"
#include "vec3.h"

void rotmx0_update(double mx[9], double mx1[9], double phi, int axis){

void rotmx0_update(double mx[9], double phi, int axis){
double c = cos(phi);
double s = sin(phi);
double ms[3][9]={
{ 1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c },
{ c, 0.0, -s, 0.0, 1.0, 0.0, s, 0.0, c },
{ c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0 }
};
veccp(9, mx1, ms[axis]);
mx3_lmultmx(ms[axis], mx);
return;
}

double mx0[9];
veccp(9, mx0, mx);
mx_multmx(3,3,3, mx, mx1, mx0);
void rot3d(int n, double * v, const double * r, const double m[9]){
for(int i=0; i<n; i++){
r3mx(v+3*i, r+3*i, m);
}
return;
}

void rot3d(int n, double * r, double m[9]){
void rot3d_inplace(int n, double * r, const double m[9]){
for(int i=0; i<n; i++){
double v[3];
r3mx(v, r+3*i, m);
Expand Down Expand Up @@ -54,3 +56,11 @@ void rot_around_perp(double rot[9], double dx, double dy, double factor){
rotmx(rot, u, factor*l);
return;
}

void mx3_lmultmx(const double A[9], double B[9]){
// B := A * B
double t[9];
mx_multmx(3,3,3, t, A, B);
veccp(9, B, t);
return;
}
73 changes: 0 additions & 73 deletions src/math/vec2.h

This file was deleted.

45 changes: 26 additions & 19 deletions src/math/vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ static inline void r3set (double * u, double s){
return;
}

static inline double r3dot (double * u, double * v){
static inline double r3dot (const double * u, const double * v){
return (u[0]*v[0] + u[1]*v[1] + u[2]*v[2]);
}

static inline double r3d2 (double * u, double * v){
static inline double r3d2 (const double * u, const double * v){
return (u[0]-v[0])*(u[0]-v[0]) +
(u[1]-v[1])*(u[1]-v[1]) +
(u[2]-v[2])*(u[2]-v[2]);
(u[2]-v[2])*(u[2]-v[2]);
}

static inline void r3x (double * w, double * u, double * v){
Expand All @@ -29,42 +29,49 @@ static inline void r3x (double * w, double * u, double * v){
return;
}

static inline void r3mx (double * u, double * v, double * m){
static inline void r3mx (double * u, const double * v, const double * m){
u[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2];
u[1] = v[0]*m[3] + v[1]*m[4] + v[2]*m[5];
u[2] = v[0]*m[6] + v[1]*m[7] + v[2]*m[8];
return;
}

static inline void r3mxt (double * u, const double * v, const double * m){
u[0] = v[0]*m[0] + v[1]*m[3] + v[2]*m[6];
u[1] = v[0]*m[1] + v[1]*m[4] + v[2]*m[7];
u[2] = v[0]*m[2] + v[1]*m[5] + v[2]*m[8];
return;
}

static inline void r3scal (double * u, double c){
u[0] *= c;
u[1] *= c;
u[2] *= c;
return;
}

static inline void r3adds (double * u, double * v, double c){
static inline void r3adds (double * u, const double * v, double c){
u[0] += c*v[0];
u[1] += c*v[1];
u[2] += c*v[2];
return;
}

static inline void r3add (double * u, double * v){
static inline void r3add (double * u, const double * v){
u[0] += v[0];
u[1] += v[1];
u[2] += v[2];
return;
}

static inline void r3min (double * u, double * v){
static inline void r3min (double * u, const double * v){
u[0] -= v[0];
u[1] -= v[1];
u[2] -= v[2];
return;
}

static inline void r3sum (double * w, double * u, double * v){
static inline void r3sum (double * w, const double * u, const double * v){
w[0] = u[0] + v[0];
w[1] = u[1] + v[1];
w[2] = u[2] + v[2];
Expand All @@ -78,28 +85,28 @@ static inline void r3diff (double * w, double * u, double * v){
return;
}

static inline void r3cp (double * u, double * v){
static inline void r3cp (double * u, const double * v){
u[0] = v[0];
u[1] = v[1];
u[2] = v[2];
return;
}

static inline void r3sums (double * w, double * u, double s, double * v, double t){
static inline void r3sums (double * w, const double * u, double s, const double * v, double t){
w[0] = u[0]*s + v[0]*t;
w[1] = u[1]*s + v[1]*t;
w[2] = u[2]*s + v[2]*t;
return;
}

static inline void r3sums3 (double * w, double * u1, double s1, double * u2, double s2, double * u3, double s3){
static inline void r3sums3 (double * w, const double * u1, double s1, const double * u2, double s2, const double * u3, double s3){
w[0] = u1[0]*s1 + u2[0]*s2 + u3[0]*s3;
w[1] = u1[1]*s1 + u2[1]*s2 + u3[1]*s3;
w[2] = u1[2]*s1 + u2[2]*s2 + u3[2]*s3;
return;
}

static inline void r3cpsc (double * u, double * v, double c){
static inline void r3cpsc (double * u, const double * v, double c){
u[0] = v[0]*c;
u[1] = v[1]*c;
u[2] = v[2]*c;
Expand All @@ -113,29 +120,29 @@ static inline void r3shift(double * u, double s){
return;
}

static inline double r3sumcomp(double * u){
static inline double r3sumcomp(const double * u){
return u[0]+u[1]+u[2];
}

static inline double r3v(double * u){
static inline double r3v(const double * u){
return u[0]*u[1]*u[2];
}

static inline void r3divcomp(double * w, double * u, double * v){
static inline void r3divcomp(double * w, const double * u, const double * v){
w[0] = u[0] / v[0];
w[1] = u[1] / v[1];
w[2] = u[2] / v[2];
return;
}

static inline void r3multcomp(double * w, double * u, double * v){
static inline void r3multcomp(double * w, const double * u, const double * v){
w[0] = u[0] * v[0];
w[1] = u[1] * v[1];
w[2] = u[2] * v[2];
return;
}

static inline void r3outer(double * w, double * u, double * v){
static inline void r3outer(double * w, const double * u, const double * v){
/* w = u * v^T
* w[i,j] = u[i]*v[j]
*/
Expand All @@ -151,7 +158,7 @@ static inline void r3outer(double * w, double * u, double * v){
return;
}

static inline void r3outer6(double * w, double * u, double * v){
static inline void r3outer6(double * w, const double * u, const double * v){
w[0] = u[0] * v[0];
w[1] = u[0] * v[1];
w[2] = u[1] * v[1];
Expand All @@ -161,7 +168,7 @@ static inline void r3outer6(double * w, double * u, double * v){
return;
}

static inline double mat3det(double * mat){
static inline double mat3det(const double * mat){
return mat[0]*mat[4]*mat[8] + mat[1]*mat[5]*mat[6] + mat[2]*mat[3]*mat[7] - mat[2]*mat[4]*mat[6] - mat[1]*mat[3]*mat[8] - mat[0]*mat[5]*mat[7];
}

Loading
Loading