def get_dihedral(ptI, ptJ, ptK, ptL, return_cross=False): """ Define a dihedral/improper between the points I, J, K and L. Defines the planes IJK and JKL (if improper is intended to be used, consider right order of atoms). Sources: http://cbio.bmt.tue.nl/pumma/index.php/Theory/Potentials http://www.vitutor.com/geometry/distance/line_plane.html http://kitchingroup.cheme.cmu.edu/blog/2015/01/18/Equation-of-a-plane-through-three-points/ """ if not isinstance(ptI, np.ndarray): ptI = np.array(ptI) if not isinstance(ptJ, np.ndarray): ptJ = np.array(ptJ) if not isinstance(ptK, np.ndarray): ptK = np.array(ptK) if not isinstance(ptL, np.ndarray): ptL = np.array(ptL) # plane IJK v1 = ptI - ptJ v2 = ptJ - ptK # the cross product v1xv2 is a vector normal to both vectors (i.e. to the plane) cp1 = np.cross(v1, v2) # plane JKL v1 = ptJ - ptK v2 = ptJ - ptL cp2 = np.cross(v1, v2) # angle between two planes is the same as the two vectors which are orthogonal # to each plane if return_cross is True: return (cgt.angle_between_vectors(cp1, cp2), cp1, cp2) else: return cgt.angle_between_vectors(cp1, cp2)
def get_angle(ptI, ptJ, ptK): """ Bla. Get angle between three points I, J and K. """ if not isinstance(ptI, np.ndarray): ptI = np.array(ptI) if not isinstance(ptJ, np.ndarray): ptJ = np.array(ptJ) if not isinstance(ptK, np.ndarray): ptK = np.array(ptK) v1 = ptI - ptJ v2 = ptK - ptJ return cgt.angle_between_vectors(v1, v2)
args = parser.parse_args() cbz = agum.Unification() cbz.read_lmpdat(args.lmpdat) cbz.import_dcd(args.dcd) cbz.read_frames(frame=args.start) with open(args.out, "w") as f_out: f_out.write("{:>9}{:>17}{:>17}{:>17}{:>17}\n".format( "Step", "ang_C13_N8_C5", "ang_C13_N8_C9", "ang_C9_N8_C5", "ang_b1_N8_b2")) for n, frame in enumerate(cbz.ts_coords[args.start:]): # omega-1/-2/-3 - angles between carbon and nitrogen ang_C13_N8_C5 = cgt.angle_between_vectors(frame[24] - frame[15], frame[24] - frame[7]) ang_C13_N8_C9 = cgt.angle_between_vectors(frame[24] - frame[15], frame[24] - frame[25]) ang_C9_N8_C5 = cgt.angle_between_vectors(frame[24] - frame[25], frame[24] - frame[7]) # phi - angle between benzenes' center of masses com_b1 = agg.get_com( [frame[14], frame[16], frame[18], frame[20], frame[22], frame[15]], [ cbz.atm_types[cbz.atoms[14].atm_key].weigh, cbz.atm_types[cbz.atoms[16].atm_key].weigh, cbz.atm_types[cbz.atoms[18].atm_key].weigh, cbz.atm_types[cbz.atoms[20].atm_key].weigh, cbz.atm_types[cbz.atoms[22].atm_key].weigh, cbz.atm_types[cbz.atoms[15].atm_key].weigh