Path: blob/main/scripts/hecke_algebras/hecke_algebras_single_orbit_data.py
1128 views
# -*- coding: utf-8 -*-1""" Complete the entries for orbits of a given Hecke algebra.23Author: Samuele Anni4"""56import os78from pymongo.mongo_client import MongoClient9C= MongoClient(port=37010)10import yaml11pw_dict = yaml.load(open(os.path.join(os.getcwd(), "passwords.yaml")))12username = pw_dict['data']['username']13password = pw_dict['data']['password']14C['hecke_algebras'].authenticate('editor', password)15hecke_orb = C['hecke_algebras'].hecke_algebras_orbits161718def do_import(ll):19Zbasis,discriminant,disc_fac,Qbasis,Qalg_gen=ll20mykeys = ['Zbasis','discriminant','disc_fac','Qbasis','Qalg_gen']21data = {}22for j in range(len(mykeys)):23data[mykeys[j]] = ll[j]24data['Zbasis']=[[str(i) for i in j] for j in data['Zbasis']]25data['discriminant']=str(data['discriminant'])26data['disc_fac']=[[str(i) for i in j] for j in data['disc_fac']]27data['Qbasis']=[int(i) for i in data['Qbasis']]28data['Qalg_gen']=[int(i) for i in data['Qalg_gen']]29return data303132def check_orbit_data(orbit_label, ll, fix=False):33query = {}34query['orbit_label'] = str(orbit_label)3536if hecke_orb.find(query).count()>1:37print("Check the orbit %s: multiple label assigned" %orbit_label)38else:39orb = hecke_orb.find_one(query)40print("Hecke orbit with label %s" % (orbit_label))41if orb is None:42print("No orbit")43return None44print("Checking whether the data is stored..." )45if 'Zbasis' not in orb.keys():46print("NOT stored")47if fix:48d = do_import(ll)49hecke_orb.update({"_id": orb["_id"]}, {"$set":{'Zbasis':d['Zbasis'],'discriminant':d['discriminant'],'disc_fac':d['disc_fac'],'Qbasis':d['Qbasis'],'Qalg_gen':d['Qalg_gen']}}, upsert=True)50print("Fixed orbit label %s" % (orbit_label))51else:52print("Already stored")535455