def send_email(sid, iid, to, cc, smtpserver='smtp.gmail.com:587'): from_addr = "*****@*****.**" login = "******" password = "******" subject = "SICP Application Received" #to = "*****@*****.**" sname, iname = adb.get_name(sid, iid) message = """Hello,\nAn applicant, {}, has applied to your position {}. Please review this application on your home page.\n\nThank you,\nSICP Administration""".format(sname, iname) msg = MIMEMultipart() msg['From'] = from_addr msg['To'] = to msg['Subject'] = subject msg.attach(MIMEText(message, 'plain')) server = smtplib.SMTP(smtpserver) server.ehlo() server.starttls() server.ehlo() server.login(login, password) text = msg.as_string() problems = server.sendmail(from_addr, to, text) server.quit()
def loadall(self, filename): with open(filename, 'r') as hisfile: spl_file = hisfile.readlines() atoms, frames = [], [] pbc = (float(spl_file[1].split()[0]), float(spl_file[2].split()[1]), float(spl_file[3].split()[2])) nat = int(spl_file[0].split()[2]) splitted_traj = [ spl_file[line_n * (2 * nat + 4):line_n * (2 * nat + 4) + (2 * nat + 4)] for line_n in range(int(len(spl_file) / (2 * nat + 4))) ] for at_n in range(nat): atom = splitted_traj[0][4:][2 * at_n].split()[0] if atom == 'OW' or atom == 'HW': atom = atom[0] atoms.append(periodic_table[db.get_name(atom)].atnum) for frame in splitted_traj: coordset = [] for at_n in range(nat): coords = frame[4:][2 * at_n + 1].split() coordset.append(np.array([float(coord) for coord in coords])) frames.append(coordset) return atoms, frames, nat, pbc
def wrap_h2o(self, frame): def pbc(oxygen, hydrogen): xx = np.linalg.norm(oxygen[0] - hydrogen[0]) yy = np.linalg.norm(oxygen[1] - hydrogen[1]) zz = np.linalg.norm(oxygen[2] - hydrogen[2]) delta = [xx, yy, zz] delta = np.array([ delta[i] - round(delta[i] / self.pbc[i]) * self.pbc[i] for i in range(3) ]) print(delta) hydrogen = oxygen + delta print(hydrogen) return hydrogen for at in range(self.nat): if self.atoms[at] == 8: self.frames[frame][at + 1] = pbc(self.frames[frame][at], self.frames[frame][at + 1]) self.frames[frame][at + 2] = pbc(self.frames[frame][at], self.frames[frame][at + 2]) with open('wrapped.xyz', 'a+') as output: output.write( F" {self.nat}\n {' '.join(self.energies[frame].split())}\n") for at, coord in enumerate(self.frames[frame]): label = periodic_table[db.get_name(self.atoms[at])].label output.write(F'{label} {coord[0]} {coord[1]} {coord[2]}\n')
def mainloop(InnerFun, timeout=30, block=['None']): people = db.get_contacts() [people.remove(i) if i != 'None' else people for i in block] while True: try: for contact in range(1, 18): #Tener al menos 18 contactos db.extract_data(contact) if db.newMsg() and db.get_name() in people: #CHAT FIJADO hl.open_conversation(db.get_xpath_num(contact)) text = db.get_message() response = InnerFun(text) hl.write(response, db.get_xpath_num(contact)) hl.open_conversation(db.get_xpath_num(contact + 1)) except: hl.refresh() hl.wait_until_window(timeout) people = db.get_contacts() [people.remove(i) if i != 'None' else people for i in block]
def coordprint(self, frame, save=False): if save: with open('output.xyz', 'a+') as output: output.write( F" {self.nat}\n {' '.join(self.energies[frame].split())}\n" ) for at, coord in enumerate(self.frames[frame]): label = periodic_table[db.get_name(self.atoms[at])].label output.write( F'{label:<2} {coord[0]:13.8f} {coord[1]:13.8f} {coord[2]:13.8f}\n' ) else: print(F" {self.nat}\n {' '.join(self.energies[frame].split())}") for at, coord in enumerate(self.frames[frame]): label = periodic_table[db.get_name(self.atoms[at])].label print( F'{label:<2} {coord[0]:13.8f} {coord[1]:13.8f} {coord[2]:13.8f}' )
def employerViewSpecificInt(iid): if escape(session['type']) == 'employer': cid = adb.get_cid(escape(session['uname'])) if adb.check_ci_ids(cid, iid): studs = students_applied(iid) sname, iname = adb.get_name(iid=iid) return render_template('employerviewinternshipsiid.html', students=studs, iid=iid, posname=iname) return redirect('/Employer')
def make_announcement(access): if not database.valid_access(access): return render_template("error.html", error="Page not found.") elif access != session["access"] and not database.is_admin(session["access"]): return redirect(url_for("unauthorized")) name = request.form["name"] text = request.form["statement"] viewable = request.form["view"] date = datetime.datetime.now() poster = database.get_name(session["email"]) database.make_announcement(date=date, name=name, text=text, poster=poster, group=viewable) return redirect(url_for("edit_all", access=access, editing="announce"))
def classinfo(): if not session.has_key('user'): return redirect(url_for("about")) username=session['user'] name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) schedule=database.get_schedule(username) classes=database.get_class_info() if request.method=='GET': return render_template("class.html" ,name=name ,osis=osis ,digits=digits ,email=email ,classes=classes ,schedule=schedule ,get=True) if request.method=="POST": value=request.form['button'] value=value.split(" ") index=int(value[1])-1 validate=True if (str(value[0])=="set"): period=classes[index][0] clas=classes[index] schedule=database.get_schedule(username) if schedule[int(period)-1][1]=="free": database.set_period(username,period,clas) else: validate=False if (str(value[0])=="req"): req=classes[index] period=classes[index][0] if database.has_lunch(username,period) or l_equal(schedule[int(period)-1],req): validate=False else: database.post_request(username,req) return render_template("class.html" ,name=name ,osis=osis ,digits=digits ,email=email ,classes=classes ,schedule=schedule ,validate=validate)
def atcount(self): """ Counts the atom frequency. Returns ------- atcount: dict Dict with the atom labels as keys and the frequencies as values. """ at_cnt = {} for at_typ in self.atomtypes: cnt = 0 for atom in self.atoms: if atom == at_typ: cnt += 1 at_cnt[db.get_name(at_typ)] = cnt del cnt return at_cnt
def profile(): if not session.has_key('user'): return redirect(url_for('about')) username=session['user'] name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) schedule=database.get_schedule(username) notif=database.get_notification(username) if request.method=='GET': return render_template("profile.html" ,name=name ,osis=osis ,digits=digits ,schedule=schedule ,email=email ,accept=notif["accept"] ,accepted=notif["accepted"] ) elif request.method=="POST": value=request.form["button"] value=value.split(" ") index=int(value[1])-1 if str(value[0])=="drop": schedule=database.get_schedule(username) clas=schedule[index] if not (clas[1]=="free" or clas[1]=="Cafe"): database.drop_period(username,clas[0]) schedule=database.get_schedule(username) return render_template("profile.html" ,name=name ,osis=osis ,digits=digits ,schedule=schedule ,email=email ,accept=notif["accept"] ,accepted=notif["accepted"] )
def visit(username=""): if not session.has_key('user'): return redirect(url_for('about')) me=session['user'] if str(username)==str(me): return redirect(url_for('profile')) name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) schedule=database.get_schedule(username) notif=database.get_notification(username) if request.method=='GET': return render_template("visit.html" ,name=name ,osis=osis ,digits=digits ,schedule=schedule ,email=email ,accept=notif["accept"] ,accepted=notif["accepted"] )
def loadall(self, filename): """ Loads the XYZ trajectory file. Parameters ---------- filename: str Name of the XYZ file. Returns ------- atoms: list List of int of the atomic numbers in order of appearance. frames: list List of np.arrays of the coordinates. energies: list List of str containing the comment line of the XYZ file. nat: int Number of atoms. """ with open(filename, 'r') as xyzfile: spl_file = xyzfile.readlines() atoms, frames, energies = [], [], [] nat = int(spl_file[0]) splitted_traj = [ spl_file[line_n * (nat + 2):line_n * (nat + 2) + (nat + 2)] for line_n in range(int(len(spl_file) / (nat + 2))) ] for at in splitted_traj[0][2:]: atom = at.split() atoms.append(periodic_table[db.get_name(atom[0])].atnum) for frame in splitted_traj: conf = self.XYZFrame(frame, en=True) frames.append(conf.coordset) energies.append(conf.energy) return atoms, frames, energies, nat
from database import get_name name = get_name()
def cdf(xyzfile, atom1, atom2, atom3, r_range, th_range): atom1 = get_name(atom1) atom2 = get_name(atom2) atom3 = get_name(atom3) at1_cnt = xyzfile.atcount[atom1] at2_cnt = xyzfile.atcount[atom2] at3_cnt = xyzfile.atcount[atom3] atom1 = periodic_table[atom1].atnum atom2 = periodic_table[atom2].atnum atom3 = periodic_table[atom3].atnum triples = [] for at1_n, at1 in enumerate(xyzfile.atoms): if at1 == atom1: for at2_n, at2 in enumerate(xyzfile.atoms): if at2 == atom2 and at2_n != at1_n: # for at3_n, at3 in enumerate(xyzfile.atoms): # if at3 == atom2 and at3_n != at1_n and at3_n != at2_n: for at3_n, at3 in enumerate(xyzfile.atoms): if at3 == atom3 and at3_n != at1_n and at3_n != at2_n: triples.append((at1_n, at2_n, at3_n)) print("Triples generated.") print(triples) dists = [] angles = [] for frame in xyzfile.frames: for triple in triples: dx12 = frame[triple[0]][0] - frame[triple[1]][0] dy12 = frame[triple[0]][1] - frame[triple[1]][1] dz12 = frame[triple[0]][2] - frame[triple[1]][2] dx13 = frame[triple[0]][0] - frame[triple[2]][0] dy13 = frame[triple[0]][1] - frame[triple[2]][1] dz13 = frame[triple[0]][2] - frame[triple[2]][2] dx23 = frame[triple[1]][0] - frame[triple[2]][0] dy23 = frame[triple[1]][1] - frame[triple[2]][1] dz23 = frame[triple[1]][2] - frame[triple[2]][2] ############################ # Minimum Image Convention # ############################ dx13 = dx13 - round(dx12 / xyzfile.pbc[0]) * xyzfile.pbc[0] dy13 = dy13 - round(dy12 / xyzfile.pbc[1]) * xyzfile.pbc[1] dz13 = dz13 - round(dz12 / xyzfile.pbc[2]) * xyzfile.pbc[2] dx12 = dx12 - round(dx12 / xyzfile.pbc[0]) * xyzfile.pbc[0] dy12 = dy12 - round(dy12 / xyzfile.pbc[1]) * xyzfile.pbc[1] dz12 = dz12 - round(dz12 / xyzfile.pbc[2]) * xyzfile.pbc[2] ############################ delta12 = dx12**2 + dy12**2 + dz12**2 delta13 = dx13**2 + dy13**2 + dz13**2 delta23 = dx23**2 + dy23**2 + dz23**2 d_12 = math.sqrt(delta12) d_13 = math.sqrt(delta13) d_23 = math.sqrt(delta23) dists.append(d_12) print(d_13, d_12, d_23) angles.append(geom.cosrule(d_23, d_12, d_13, deg=True)) print("Distances and angles calculated.") print(len(angles)) print(angles) cdf, dist, angle = np.histogram2d(dists, angles, bins=(r_range[2], th_range[2]), range=(r_range[:2], th_range[:2])) # with open('before_norm.dat', 'w+') as outfile: # for row in range(len(cdf)): # for col in range(len(cdf[0])): # outfile.write(F'{dist[row]} {angle[col]} {cdf[row][col]}\n') ################# # Normalization # ################# def volume(r_range, th_range): th_range = list(map(lambda x: x * (math.pi / 180), th_range)) volume = (2 / 3) * math.pi * (pow(r_range[1], 3) - pow( r_range[0], 3)) * (math.cos(th_range[0]) - math.cos(th_range[1])) return volume rho = at2_cnt / (xyzfile.pbc[0] * xyzfile.pbc[1] * xyzfile.pbc[2]) norm = 2 * xyzfile.nframes * at1_cnt * rho # print(norm, xyzfile.nframes, at1_cnt, at2_cnt, rho, xyzfile.pbc) plt_dist = [] plt_angle = [] plt_cdf = [] for row in range(len(cdf)): for col in range(len(cdf[0])): # cdf[row][col] /= (norm*volume((dist[row], dist[row + 1]), (angle[col], angle[col + 1]))) plt_dist.append(dist[row]) plt_angle.append(angle[col]) plt_cdf.append(cdf[row][col]) print("Normalized.") ################# print(sum(plt_cdf)) # cdf = cdf.T fig, ax = plt.subplots() ax.scatter(plt_dist, plt_angle, c=plt_cdf) #, s=30) # ax.imshow(cdf, interpolation='nearest', origin='low', extent=[dist[0], dist[-1], angle[0], angle[-1]]) plt.show()
def rdf(xyzfile, atom1, atom2, start, stop, nbins, outfile="out_rdf.dat"): assert start >= 0, "The starting value of the rdf has to be positive." assert stop > start, "The final value of the rdf has to be greater than the starting one." #! ENTER PBC CONDITION, THROW ERROR atom1 = get_name(atom1) atom2 = get_name(atom2) at1_cnt = xyzfile.atcount[atom1] at2_cnt = xyzfile.atcount[atom2] atom1 = periodic_table[atom1].atnum atom2 = periodic_table[atom2].atnum dr = (stop - start) / nbins couples = corr_cpp.couples(xyzfile.atoms, atom1, atom2) dists = corr_cpp.dists(xyzfile.frames, xyzfile.pbc, couples) ''' couples = [] for at1_n, at1 in enumerate(xyzfile.atoms): if at1 == atom1: for at2_n, at2 in enumerate(xyzfile.atoms): if at2 == atom2 and at2_n != at1_n: #this last bool checks for rdf with itself couples.append((at1_n, at2_n)) dists = [] for frame in xyzfile.frames: for couple in couples: dx = frame[couple[0]][0] - frame[couple[1]][0] dy = frame[couple[0]][1] - frame[couple[1]][1] dz = frame[couple[0]][2] - frame[couple[1]][2] ############################ # Minimum Image Convention # ############################ dx = dx - round(dx / xyzfile.pbc[0]) * xyzfile.pbc[0] dy = dy - round(dy / xyzfile.pbc[1]) * xyzfile.pbc[1] dz = dz - round(dz / xyzfile.pbc[2]) * xyzfile.pbc[2] ############################ delta = dx**2 + dy**2 + dz**2 d_ij = math.sqrt(delta) dists.append(d_ij) ''' rdf = list(np.histogram(dists, nbins, range=(start, stop))) ################# # Normalization # ################# rho = at2_cnt / (xyzfile.pbc[0] * xyzfile.pbc[1] * xyzfile.pbc[2]) norm = 4 * math.pi * rho * dr * xyzfile.nframes * at1_cnt if start == 0: rdf[0] = list( map(lambda x, y: x / (norm * y**2), rdf[0][1:], rdf[1][1:-1])) else: rdf[0] = list(map(lambda x, y: x / (norm * y**2), rdf[0], rdf[1][:-1])) ################# with open(outfile, 'w+') as outfile: for n in range(len(rdf[0])): outfile.write(F'{rdf[1][n]} {rdf[0][n]}\n')
def tradingfloor(): if not session.has_key('user'): return redirect(url_for("about")) username=session['user'] name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) database.refresh_floor() floor=database.get_floor() if request.method=='GET': return render_template("trading.html" ,name=name ,osis=osis ,digits=digits ,floor=floor ,email=email ,validate=False) if request.method=='POST': value=request.form["button"] value=value.split(" ") index=int(value[1])-1 req=floor[index]["request"] period=int(req[0])-1 acceptername=username postername=floor[index]['username'] schedule=database.get_schedule(username)[period] validate=False myself=False illegaldel=False try: if not str(postername)==str(username): if value[0]=="accept": if l_equal(req,schedule): database.accept_request(postername,acceptername,req) return redirect(url_for("tradingfloor")) else: validate=True elif value[0]=="delete": validate=True myself=False illegaldel=True else: if value[0]=="accept": validate=True myself=True else: database.remove_request(username,req) database.refresh_floor() floor=database.get_floor() return render_template("trading.html" ,name=name ,osis=osis ,digits=digits ,email=email ,floor=floor ,validate=validate ,myself=myself ,illegaldel=illegaldel) except Exception: return render_template("trading.html" ,name=name ,osis=osis ,digits=digits ,email=email ,floor=floor ,validate=True)