def main(): λx = 40 λy = 50 λz = 20 Tx = 3.797 Ty = 11.312 Tz = 2.045 n = 100 points = numpy.empty((n, 3)) points[:, 0] = 2. * numpy.sin(numpy.arange(n) * 2 * math.pi / λx) points[:, 1] = 2. * numpy.sin(numpy.arange(n) * 2 * math.pi / λy) points[:, 2] = 2. * numpy.sin(numpy.arange(n) * 2 * math.pi / λz) basepoints = points.copy() curve = vis.curve(pos=points, color=vis.color.red, radius=0.1) fps = 30 t = 0. while True: points = basepoints * numpy.array([ numpy.cos(2 * math.pi * t / Tx), numpy.cos(2 * math.pi * t / Ty), numpy.cos(2 * math.pi * t / Tz) ]) curve.points = points vis.rate(30) t += 1. / fps
def main(): l = 0.5 verts = numpy.array( [ [-l, 0, -l], [ l, 0, -l], [-l, 0, l], [-l, 0, l], [ l, 0, -l], [ l, 0, l], [-l, 0, l], [ 0, 1.5*l, 0 ], [-l, 0, -l], [ l, 0, l], [ 0, 1.5*l, 0 ], [-l, 0, l], [ l, 0, -l], [ 0, 1.5*l, 0 ], [ l, 0, l], [-l, 0, -l], [ 0, 1.5*l, 0 ], [ l, 0, -l] ] ) pyr = vis.faces(verts, color=vis.color.red) while (True): vis.rate(30)
def main(): file_name = str(sys.argv[1]) read_txt_file(file_name) translation_vec = np.array([0., 0., 0.]) for atom in atom_builder.all_atoms: translation_vec += atom.pos translation_vec /= len(atom_builder.all_atoms) for atom in atom_builder.all_atoms: atom.pos -= translation_vec for vis_atom in visual.all_visual_atoms: vis_atom.visual.pos = vis_atom.atom_object.pos for bond in visual.all_visual_bonds: bond.visual.pos = bond.bond_object.atom1.pos bond.visual.axis = bond.bond_object.atom2.pos - bond.bond_object.atom1.pos for atom in atom_builder.all_atoms: if atom.atom_type == 'NH1': amine_nitrogen = atom if atom.atom_type == 'CT1': central_carbon = atom for bond in bond_builder.all_bonds: if bond.atom1.atom_type or bond.atom2.atom_type == 'C': if bond.atom1.atom_type == 'O': carbonyl_carbon = bond.atom2 if bond.atom2.atom_type == 'O': carbonyl_carbon = bond.atom1 vis.label(text = 'N', pos = amine_nitrogen.pos, height = 3, font = 'serif', color = [1., 0., 0.], box = False, units = "centidisplay", yoffset = 5, xoffset = 2) vis.label(text = 'C', pos = central_carbon.pos, height = 3, font = 'serif', color = [0., 1., 0.], box = False, units = "centidisplay", yoffset = 5, xoffset = 2) vis.label(text = 'C', pos = carbonyl_carbon.pos, height = 3, font = 'serif', color = [0., 0., 1.], box = False, units = "centidisplay", yoffset = 5, xoffset = 2) display = True disp = vis.scene() disp.foreground = [1,1,1] while display == True: vis.rate(30)
def main(): file_name = str(sys.argv[1]) read_txt_file(file_name) display = True disp = vis.scene() disp.foreground = [1, 1, 1] while display == True: vis.rate(30)
def main(): spheres = [] for i in range(2000): spheres.append( physvis.sphere(pos=(random.random() * 5 - 2.5, random.random() * 5 - 2.5, random.random() * 5 - 2.5), radius=0.05, color=(random.random(), random.random(), random.random()))) while True: physvis.rate(30)
def main(): fps = 30. endt = 3 box = vis.box() t = 0 while True: newtime = time.perf_counter() try: dtime = newtime - lasttime sys.stderr.write("fps: {}\n".format(1./dtime)) except(NameError): pass lasttime = newtime vis.rate(fps) t += 1./fps if t >= endt: return
def main(): Time_Unit = ((1.66054E-27 * 1E-20) / (1.60218E-19))**(1 / 2) Epsilon = ((1.60218E-19)**2 * (Time_Unit)**2) / ((1E-10)**3 * (1.66054E-27)) print('Time Units (seconds): {} and Epsilon: {}'.format( Time_Unit, Epsilon)) s70 = math.sin(70 / 180 * math.pi) c70 = math.cos(70 / 180 * math.pi) s120 = math.sin(120 / 180 * math.pi) c120 = math.cos(120 / 180 * math.pi) s20 = math.sin(20 / 180 * math.pi) c20 = math.cos(20 / 180 * math.pi) l0 = 1.530 l1 = 1.111 h_bond = l1 * (1 / 2)**(1 / 2) h1pos = np.array([-l1 * c70, -l1 * s70, 0.]) h2pos = np.array([-l1 * c70, -l1 * s70 * c120, l1 * s70 * s120]) h3pos = np.array([-l1 * c70, -l1 * s70 * c120, -l1 * s70 * s120]) crotang = math.cos(20. / 180. * math.pi) srotang = math.sin(20. / 180. * math.pi) rotmat = np.array([[1., 0., 0.], [ 0., crotang, -srotang, ], [0., srotang, crotang]]) h1pos = np.matmul(rotmat, h1pos) h2pos = np.matmul(rotmat, h2pos) h3pos = np.matmul(rotmat, h3pos) global vals c_1 = atom(element='carbon', element_type='CC32A', atom_number=1, y0=l0 / 2) c_2 = atom(element='carbon', element_type='CC32A', atom_number=2, y0=l0 * s20, x0=l0 * c20) c_3 = atom(element='carbon', element_type='CC32A', atom_number=3, y0=-l0 * s20, x0=l0 * c20) c_4 = atom(element='carbon', element_type='CC32A', atom_number=4, y0=-l0 / 2) c_5 = atom(element='carbon', element_type='CC32A', atom_number=5, y0=-l0 * s20, x0=-l0 * c20) c_6 = atom(element='carbon', element_type='CC32A', atom_number=6, y0=l0 * s20, x0=-l0 * c20) h_1 = atom(atom_number=7, element='hydrogen', element_type='HCA2A', x0=c_1.pos[0] - h_bond - 0.01, y0=c_1.pos[1] + h_bond, z0=.5) h_2 = atom(atom_number=8, element='hydrogen', element_type='HCA2A', x0=c_1.pos[0] + h_bond, y0=c_1.pos[1] + h_bond, z0=-0.5) h_3 = atom(atom_number=9, element='hydrogen', element_type='HCA2A', x0=c_2.pos[0] + h_bond, y0=c_2.pos[1] + h_bond) h_4 = atom(atom_number=10, element='hydrogen', element_type='HCA2A', x0=c_2.pos[0] + l1, y0=c_2.pos[1]) h_5 = atom(atom_number=11, element='hydrogen', element_type='HCA2A', x0=c_3.pos[0] + l1, y0=c_3.pos[1]) h_6 = atom(atom_number=12, element='hydrogen', element_type='HCA2A', x0=c_3.pos[0] + h_bond, y0=c_3.pos[1] - h_bond) h_7 = atom(atom_number=13, element='hydrogen', element_type='HCA2A', x0=c_4.pos[0] + h_bond, y0=c_4.pos[1] - h_bond) h_8 = atom(atom_number=14, element='hydrogen', element_type='HCA2A', x0=c_4.pos[0] - h_bond, y0=c_4.pos[1] - h_bond) h_9 = atom(atom_number=15, element='hydrogen', element_type='HCA2A', x0=c_5.pos[0] - l1, y0=c_5.pos[1]) h_10 = atom(atom_number=16, element='hydrogen', element_type='HCA2A', x0=c_5.pos[0] - h_bond, y0=c_5.pos[1] - h_bond) h_11 = atom(atom_number=17, element='hydrogen', element_type='HCA2A', x0=c_6.pos[0] - h_bond, y0=c_6.pos[1] + h_bond) h_12 = atom(atom_number=18, element='hydrogen', element_type='HCA2A', x0=c_6.pos[0] - l1, y0=c_6.pos[1]) cyclohexane_1 = molecule() cyclohexane_1.add_atom(h_1) cyclohexane_1.add_atom(h_2) cyclohexane_1.add_atom(h_3) cyclohexane_1.add_atom(h_4) cyclohexane_1.add_atom(h_5) cyclohexane_1.add_atom(h_6) cyclohexane_1.add_atom(h_7) cyclohexane_1.add_atom(h_8) cyclohexane_1.add_atom(h_9) cyclohexane_1.add_atom(h_10) cyclohexane_1.add_atom(h_11) cyclohexane_1.add_atom(h_12) cyclohexane_1.add_atom(c_1) cyclohexane_1.add_atom(c_2) cyclohexane_1.add_atom(c_3) cyclohexane_1.add_atom(c_4) cyclohexane_1.add_atom(c_5) cyclohexane_1.add_atom(c_6) cyclohexane_1.bond_atoms(h_1, c_1) cyclohexane_1.bond_atoms(h_2, c_1) cyclohexane_1.bond_atoms(h_3, c_2) cyclohexane_1.bond_atoms(h_4, c_2) cyclohexane_1.bond_atoms(h_5, c_3) cyclohexane_1.bond_atoms(h_6, c_3) cyclohexane_1.bond_atoms(h_7, c_4) cyclohexane_1.bond_atoms(h_8, c_4) cyclohexane_1.bond_atoms(h_9, c_5) cyclohexane_1.bond_atoms(h_10, c_5) cyclohexane_1.bond_atoms(h_11, c_6) cyclohexane_1.bond_atoms(h_12, c_6) cyclohexane_1.bond_atoms(c_1, c_2) cyclohexane_1.bond_atoms(c_2, c_3) cyclohexane_1.bond_atoms(c_3, c_4) cyclohexane_1.bond_atoms(c_4, c_5) cyclohexane_1.bond_atoms(c_5, c_6) cyclohexane_1.bond_atoms(c_6, c_1) for dangle in cyclohexane_1.dihedrals: print(dangle.first_atom.atom_number, '-', dangle.second_atom.atom_number, '-', dangle.third_atom.atom_number, '-', dangle.fourth_atom.atom_number) print('\n', len(cyclohexane_1.dihedrals)) # Something is v wrong with my dihedral counter. # It appears as though our worst fears have been confirmed ... # the cyclic molecule is causing me to wayyyyy over count the # number of dihedrals present. I am pretty sure that # cyclohexane should not have 121 dihedrals in it. Jake, # implement a method to fix this overcounting and you should # also fix that ValueError that you are getting in the bond # force function with the arcsin. When theta is 90 you are # getting this error. ############################################################################################ index = 0 n_atoms = 0 for mol in molecule.all_molecules: n_atoms += len(mol.atoms) vals = np.empty(6 * n_atoms) integrator = ode(ders) integrator.set_integrator("vode") for mol in molecule.all_molecules: for at in mol.atoms: at.move_data_to_buffers( vals[index:index + 3], vals[3 * n_atoms + index:3 * n_atoms + index + 3]) index += 3 t = 0 tf = 500 dt = 1E-1 t_stall = 5 integrator.set_initial_value(vals) have_already_printed = False while t < tf: integrator.integrate(t + dt) vals[:] = integrator.y visual.update_visual() while t <= t_stall: t += dt vels = [mag(atom.vel) for atom in cyclohexane_1.atoms] maxvel = max(vels) if not have_already_printed and maxvel <= 1E-5: print(maxvel) for bangle in cyclohexane_1.bond_angles: r1 = bangle.end_atom.pos - bangle.middle_atom.pos r2 = bangle.start_atom.pos - bangle.middle_atom.pos the_angle_bruh = math.acos( (r1 * r2).sum() / mag(r1) / mag(r2)) * 180. / math.pi print("{:20s} : {:.2f}°".format(bangle.typedex, the_angle_bruh)) have_already_printed = True t += dt vis.rate(30)
def main(): description = "Draw two growing curves" epilog = "Try setting fps to various different values. If your graphics system syncs to the monitor's vblank (many of them do), this will limit how many calculation updates you can have per second to that rate. At least *some* systems can disable this synchronization by setting the environment variable vblank_mode to 0; your OS and graphics card driver may have different ways to do this. Try setting fps to different values (and using -g) and playing with this to see what you can effectively get." parser = argparse.ArgumentParser(description=description, epilog=epilog) parser.add_argument( "-t", "--endt", type=float, default=10., dest="endt", help= "Run until the simulation gets to this time in seconds (default: 10)") parser.add_argument("-q", "--qt", action="store_true", default=False, dest="qt", help="Use the Qt backend (default: GLUT)") parser.add_argument( "-f", "--fps", type=int, default=60, dest="fps", help="Try to do this many updates per second (default: 60)") parser.add_argument( "-p", "--printevery", type=float, default=2., dest="printevery", help= "Print updates per second every (roughtly) this many real seconds (default: 2)" ) parser.add_argument("-g", "--gfps", action="store_true", default=False, dest="gfps", help="Print graphics frames per second") args = parser.parse_args() fps = args.fps endt = args.endt useqt = args.qt printevery = args.printevery GrContext.print_fps = args.gfps if useqt: app = qt.QApplication([]) window = qt.QWidget() vbox = qt.QVBoxLayout() window.setLayout(vbox) wid = qtgrcontext.QtGrContext() vbox.addWidget(wid, 1) window.show() curver = TwoCurves(endt=endt, fps=fps, printevery=printevery) if useqt: mainlooptimer = qtcore.QTimer() mainlooptimer.timeout.connect(lambda: curver.update(app)) mainlooptimer.start(1000. / fps) app.exec_() else: while True: curver.update(None) vis.rate(fps)