def calcAngledForce(self, angle, ff_angles): k = 1000 cost0 = -0.5 # 120 degree atom1 = angle.get_a_1() atom2 = angle.get_a_2() atom3 = angle.get_a_3() # Overwrite the hardcoded params if ff_angles is not None: t0 = ff_angles[angle.get_param()][0] cost0 = np.cos(t0 * (np.pi / 180)) # k = ff_angles[angle.get_param()][1] vecAB = self.vectorFromAtoms(atom1, atom2) vecAB = unit_vector(vecAB) vecCB = vectorFromAtoms(atom3, atom2) vecCB = unit_vector(vecCB) costeta = self.cosine_2unit_v(vecAB, vecCB) df = -k * (costeta - cost0) forceA = df * (vecCB - vecAB * costeta) forceC = df * (vecAB - vecCB * costeta) forceB = -1 * forceA - forceC self.forces[int(atom1.get_nr()) - 1] += forceA self.forces[int(atom2.get_nr()) - 1] += forceB self.forces[int(atom3.get_nr()) - 1] += forceC self.totalAngles[0] += self.calcVectorModule(forceA) self.totalAngles[1] += self.calcVectorModule(forceB) self.totalAngles[2] += self.calcVectorModule(forceC)
def calcMediaTeta(self): media = 0.0 for angle in self.top.get_angle_list(): atom1 = angle.get_a_1() atom2 = angle.get_a_2() atom3 = angle.get_a_3() vecAB = vectorFromAtoms(atom2, atom1) vecAB = unit_vector(vecAB) vecBC = vectorFromAtoms(atom2, atom3) vecBC = unit_vector(vecBC) teta = self.angle_between(vecAB, vecBC) media += teta
def calcMediaAngle(self): media = 0.0 for angle in self.top.get_angle_list(): atom1 = angle.get_a_1() atom2 = angle.get_a_2() atom3 = angle.get_a_3() vecAB = vectorFromAtoms(atom2, atom1) vecAB = unit_vector(vecAB) vecBC = vectorFromAtoms(atom2, atom3) vecBC = unit_vector(vecBC) teta = self.cosine_similarity(vecAB, vecBC) media += teta
def update(self): reward = np.dot(unit_vector(self.dir), unit_vector(self.target-self.pos)) * \ (self.init_dist-distance(self.pos, self.target))/(self.init_dist*2000) previous_state = self.state super().update() if not self.done: if self.isColliding: self.done = True reward -= 3 elif self.target_reached: self.done = True reward += 2 self.state = self.get_state() self.agent.remember(previous_state, self.last_action_id, reward, self.state, self.done) self.total_reward += reward
def calc_vect(self): self.vect = np.array([0, 0]) if not self.target_reached: self.vect = -unit_vector(self.target - self.pos) for boat in self.boatList: if not boat == self and boat.priority >= self.priority: self.vect = self.vect + gen_vect(self.pos, boat)
def calcAngledForce(self, angle): k = 1000 cost0 = -0.5 # 120 degree atom1 = angle.get_a_1() atom2 = angle.get_a_2() atom3 = angle.get_a_3() vecAB = self.vectorFromAtoms(atom1, atom2) vecAB = unit_vector(vecAB) vecCB = vectorFromAtoms(atom3, atom2) vecCB = unit_vector(vecCB) costeta = self.cosine_2unit_v(vecAB, vecCB) df = -k * (costeta - cost0) forceA = df * (vecCB - vecAB * costeta) forceC = df * (vecAB - vecCB * costeta) forceB = -1 * forceA - forceC self.forces[int(atom1.get_nr()) - 1] += forceA self.forces[int(atom2.get_nr()) - 1] += forceB self.forces[int(atom3.get_nr()) - 1] += forceC
def calcAngleEnergy(self, angle, ff_angles): k = 1000 cost0 = -0.5 # 120 degree atom1 = angle.get_a_1() atom2 = angle.get_a_2() atom3 = angle.get_a_3() #Overwrite the hardcoded params if ff_angles is not None: t0 = ff_angles[angle.get_param()][0] cost0 = np.cos(t0 * (np.pi / 180)) k = ff_angles[angle.get_param()][1] vecAB = self.vectorFromAtoms(atom1, atom2) vecAB = unit_vector(vecAB) vecCB = vectorFromAtoms(atom3, atom2) vecCB = unit_vector(vecCB) costeta = self.cosine_2unit_v(vecAB, vecCB) energy = 0.5 * k * (costeta - cost0)**2 return energy
def angle_between(self, v1, v2): v1_u = unit_vector(v1) v2_u = unit_vector(v2) return np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0))
def setPositionNeighbor(self, neighbor, atom, count, insertedNeighbors, previousAtom): bond = 0.10 if ((neighbor.get_atomtype() == 'H') or (neighbor.get_atomtype() == 'HC')) else 0.15 if previousAtom == atom: if count == 0: # print ("COUNT 0 - level 0") neighbor.setposition(atom.get_x() + bond, atom.get_y(), atom.get_z()) return if count == 1: # print ("COUNT 1 - level 0!!!") z = 1 cos = -0.5 sin = 0.866 x = atom.get_x() + bond * cos y = atom.get_y() + bond * sin neighbor.setposition(x, y, z) return if count == 2: # print("COUNT 2 - level 0!!!") v1 = unit_vector(vectorFromAtoms(insertedNeighbors[0], atom)) v2 = unit_vector(vectorFromAtoms(insertedNeighbors[1], atom)) v3 = unit_vector(np.array(v1) + np.array(v2)) position = np.array([atom.get_x(), atom.get_y(), atom.get_z()]) - bond * np.array(v3) neighbor.setposition(position[0], position[1], position[2]) return if count == 3: neighbor.setposition( atom.get_x(), atom.get_y(), atom.get_z() - 0.1 + random.uniform(0, 0.05)) return if count == 0: dihedral = self.find_dihedral(previousAtom, atom) if dihedral != None: # print("COUNT 0a - level 1!!!") otherAtom = None if dihedral.get_a_1() == neighbor: otherAtom = dihedral.get_a_4() if dihedral.get_a_4() == neighbor: otherAtom = dihedral.get_a_1() v1 = unit_vector(vectorFromAtoms(otherAtom, previousAtom)) v2 = unit_vector(vectorFromAtoms(previousAtom, atom)) v4 = unit_vector(np.cross(v1, v2)) if dihedral.get_conformation() is not None: v5 = unit_vector(np.cross(v2, v4)) if dihedral.get_conformation() == 'cis': v6 = bond * -0.5 * v2 - bond * 0.866 * -v5 else: v6 = bond * -0.5 * v2 - bond * 0.866 * v5 position = np.array([ atom.get_x(), atom.get_y(), atom.get_z() ]) + v6 neighbor.setposition(position[0], position[1], position[2]) return v5 = unit_vector(np.cross( v2, v4)) + (0, 0, random.uniform(-0.5, 0.5)) v6 = bond * -0.5 * v2 - bond * 0.866 * unit_vector(v5) position = np.array([atom.get_x(), atom.get_y(), atom.get_z()]) + v6 neighbor.setposition(position[0], position[1], position[2]) return if dihedral is None: # print("COUNT 0b - level 1!!!") cos = -0.5 sin = 0.866 x = atom.get_x() + bond * cos y = atom.get_y() + bond * sin z = atom.get_z() neighbor.setposition(x, y, z) return if count == 1: # print("COUNT 1 - level 1!!!") sp3angle = math.radians(109.5) v2 = unit_vector(vectorFromAtoms(previousAtom, atom)) v3 = unit_vector(vectorFromAtoms(insertedNeighbors[0], atom)) v4 = unit_vector(-(v2 + v3)) v5 = np.cross(v2, v3) position = np.array([atom.get_x( ), atom.get_y(), atom.get_z()]) + bond * math.sin( 0.5 * sp3angle) * v5 + bond * math.cos(0.5 * sp3angle) * v4 neighbor.setposition(position[0], position[1], position[2]) return if count == 2: # print("COUNT 2 - level 1!!!") v1 = unit_vector(vectorFromAtoms(previousAtom, atom)) v2 = unit_vector(vectorFromAtoms(insertedNeighbors[0], atom)) v3 = unit_vector(vectorFromAtoms(insertedNeighbors[1], atom)) v4 = v1 + v2 + v3 position = np.array([atom.get_x(), atom.get_y(), atom.get_z()]) - bond * np.array(v4) neighbor.setposition(position[0], position[1], position[2]) return
def setPositionNeighbor(self, neighbor, atom, count, insertedNeighbors, previousAtom): bond = 0.10 if ((neighbor.get_atomtype() == 'H') or (neighbor.get_atomtype() == 'HC')) else 0.15 if previousAtom == atom: if count == 0: neighbor.setposition(atom.get_x() + bond, atom.get_y(), atom.get_z()) return if count == 1: z = 1 cos = -0.5 sin = 0.866 x = atom.get_x() + bond * cos y = atom.get_y() + bond * sin neighbor.setposition(x, y, z) return if count == 2: v1 = unit_vector(vectorFromAtoms(previousAtom, atom)) v2 = unit_vector(vectorFromAtoms(insertedNeighbors[0], atom)) v3 = unit_vector(np.array(v1) + np.array(v2)) position = np.array([atom.get_x(), atom.get_y(), atom.get_z()]) - bond * np.array(v3) neighbor.setposition(position[0], position[1], position[2]) return if count == 3: neighbor.setposition( atom.get_x(), atom.get_y(), atom.get_z() - 0.1 + random.uniform(0, 0.05)) return if count == 0: dihedral = self.find_dihedral(previousAtom, atom) otherAtom = None if dihedral.get_a_1() == neighbor: otherAtom = dihedral.get_a_4() if dihedral.get_a_4() == neighbor: otherAtom = dihedral.get_a_1() v1 = unit_vector(vectorFromAtoms(otherAtom, previousAtom)) v2 = unit_vector(vectorFromAtoms(previousAtom, atom)) v4 = unit_vector(np.cross(v1, v2)) if dihedral.get_conformation() is not None: v5 = unit_vector(np.cross(v2, v4)) if dihedral.get_conformation() == 'cis': v6 = bond * -0.5 * v2 - bond * 0.866 * -v5 else: v6 = bond * -0.5 * v2 - bond * 0.866 * v5 position = np.array([atom.get_x(), atom.get_y(), atom.get_z()]) + v6 neighbor.setposition(position[0], position[1], position[2]) return v5 = unit_vector(np.cross(v2, v4)) + (0, 0, random.uniform(-0.5, 0.5)) v6 = bond * -0.5 * v2 - bond * 0.866 * unit_vector(v5) position = np.array([atom.get_x(), atom.get_y(), atom.get_z()]) + v6 neighbor.setposition(position[0], position[1], position[2]) return if count == 1: v1 = unit_vector(vectorFromAtoms(previousAtom, atom)) v2 = unit_vector(vectorFromAtoms(insertedNeighbors[0], atom)) v3 = unit_vector(np.array(v1) + np.array(v2)) position = np.array([atom.get_x(), atom.get_y(), atom.get_z()]) - bond * np.array(v3) neighbor.setposition(position[0], position[1], position[2]) return if count == 2: v1 = unit_vector(vectorFromAtoms(previousAtom, atom)) v2 = unit_vector(vectorFromAtoms(insertedNeighbors[0], atom)) v3 = unit_vector(vectorFromAtoms(insertedNeighbors[1], atom)) v4 = unit_vector(np.cross(v1, v2)) position = np.array([atom.get_x(), atom.get_y(), atom.get_z()]) - bond * np.array(v4) neighbor.setposition(position[0], position[1], position[2]) return