d = np.zeros((N,3), dtype='double') ifail = np.zeros(1, dtype='int') # Use above to find d. Solve Ax=b for x. code = """ for(int i=0; i<N; i++) { double *A = M+i*9; double *b = F+i*3; double *x = d+i*3; double det=A[0]*A[4]*A[8]+A[1]*A[5]*A[6] +A[3]*A[7]*A[2]-A[2]*A[4]*A[6] -A[0]*A[5]*A[7]-A[8]*A[1]*A[3]; if (abs(det)<1.0e-14) *ifail = 1; *(x++)=(b[0]*A[4]*A[8]+A[1]*A[5]*b[2]+b[1]*A[7]*A[2]-A[2]*A[4]*b[2]-b[0]*A[5]*A[7]-A[8]*A[1]*b[1])/det; *(x++)=(A[0]*b[1]*A[8]+b[0]*A[5]*A[6]+A[3]*b[2]*A[2]-A[2]*b[1]*A[6]-A[0]*A[5]*b[2]-A[8]*b[0]*A[3])/det; *(x++)=(A[0]*A[4]*b[2]+A[1]*b[1]*A[6]+A[3]*A[7]*b[0]-b[0]*A[4]*A[6]-A[0]*b[1]*A[7]-b[2]*A[1]*A[3])/det; } """ W.inline(code, ['F', 'M', 'd', 'N', 'ifail']); return d if __name__ == '__main__': model = eam_model('eam.tab', 7.0, 0.9) box, coords, ityp, ityp2, typnam = readfiles.readxyz('1_1-1.xyz') # dirty change model.set_atoms(box, coords, ityp) print model.get_energy() force = model.get_force() print force print "Pressure", model.get_pressure(), "eV/Angstrom^3" print "Pressure", model.get_pressure(GPa=True), "GPa" #force_norm = np.sqrt((force*force).sum(axis=1))
code = """ for(int k=0; k<n; k++) { int i = *(neighborlist++); int j = *(neighborlist++); double *Fi = F+i*3; double *Fj = F+j*3; *(Fi++) -= ((*dV+(*(dF+i)**(drhoj))-(*(dF+j)**(drhoi)))*(*rijhat)); *(Fi++) -= ((*dV+(*(dF+i)**(drhoj))-(*(dF+j)**(drhoi)))*(*(rijhat+1))); *(Fi++) -= ((*dV+(*(dF+i)**(drhoj))-(*(dF+j)**(drhoi)))*(*(rijhat+2))); *(Fj++) += ((*dV+(*(dF+j)**(drhoi))-(*(dF+i)**(drhoj)))*(*rijhat)); *(Fj++) += ((*dV+(*(dF+j)**(drhoi))-(*(dF+i)**(drhoj)))*(*(rijhat+1))); *(Fj++) += ((*dV+(*(dF+j)**(drhoi))-(*(dF+i)**(drhoj)))*(*(rijhat+2))); drhoi++; drhoj++; dV++; rijhat+=3; } """ W.inline(code, ["F", "dV", "drhoi", "drhoj", "rijhat", "dF", "n", "neighborlist"]) return F model = eam_model("eam.tab", 7.0, 0.9) box, coords, ityp, ityp2, typnam = readfiles.readxyz("test.xyz") # dirty change model.set_atoms(box, coords, ityp) print model.get_energy() force = model.get_force() print force # force_norm = np.sqrt((force*force).sum(axis=1))