Exemple #1
0
def check_if_particle_exist(particle):
    """
    Check if this particle is known before add it to list!
    """
    for p in Particle.objects(alias=particle):
        return p.name
    for p in Particle.objects(name=particle):
        return p.name
    return False
Exemple #2
0
def check_if_particle_exist(particle):
    """
    Check if this particle is known before add it to list!
    """
    for p in Particle.objects(alias=particle):
        return p.name
    for p in Particle.objects(name=particle):
        return p.name
    if particle in ALIAS.keys():
        return check_if_particle_exist(ALIAS[particle])
    return False
Exemple #3
0
def p_json(query):
    if query=="null":
        p_names = []
        for p in Particle.objects():
            p_names.append(p.name)
        return Response(json_dump({'p_names':p_names}), mimetype='application/json')
    p_names = []
    last = query.split(" ")[-1]
    n_tot=10
    for p in Particle.objects():
        if last == p.name[0:len(last)]:
            p_names.append(query[:-len(last)]+p.name)
            n_tot-=1
        if n_tot<1:
            break
    return Response(json_dump({'p_names':p_names}), mimetype='application/json')
Exemple #4
0
def query_with_ME(query, energy=100):
    start = datetime.now()
    queries = []
    for p in Particle.objects(mass__lt=energy):
        queries.append(query + " " + p.name)
    for q in queries:
        query_test(q, False)
    end = datetime.now()
    print "Search for " + query + " with missed energy " + str(energy) + " MeV took {}".format(end - start)
    return True
Exemple #5
0
def json(query):
    if not query:
        return redirect('/')

    query = [x for x in query.split(' ') if x != '']

    start = datetime.now()
    result = do_search(query)
    end = datetime.now()   
    for r in result:
        r['branching'] = nice_br(r['branching'])
        #r['branching'] = "%0.4g" % r['branching']   
    p_list = {}
    for p in Particle.objects():
        p_list[p.to_dict()["name"]]=p.to_print()

    return Response(json_dump({'result' : result, 'time': str(end-start), 'p_list':p_list}), mimetype='application/json')
Exemple #6
0
def save_particle_to_db(name, charge, mass, antiparticle, alias=[], antiparticle_alias=[]):
    """
    This function save particle to db.
    name - name of a partilce, string
    charge - charge of a particle, float
    mass - mass of a particle in MeV, float
    antiparticle - name of a charge-conjugate particle. 
    In case if particle is self-conjugate, antiparticle == name
    alias - possible names for this particle. 
    antiparticle_alias - possible names for its anti-particle. 
    """
    if alias == []:
        alias.append(name)        
    db_part = Particle( name = name,
                        charge = charge,
                        mass = mass,
                        alias = alias,
                        antiparticle = antiparticle)
    try: 
        db_part.save()
    except:
        print("Failed to save particle:")
        print(json.dumps(db_part.to_dict(),sort_keys=True, indent=4))
        return False
    if not antiparticle == name:
        if antiparticle_alias == []:
            antiparticle_alias.append(antiparticle)        
        db_part = Particle( name = antiparticle,
                            charge = -charge,
                            mass = mass,
                            alias = antiparticle_alias,
                            antiparticle = name)
        try: 
            db_part.save()
        except:
            print("Failed to save particle:")
            print(json.dumps(db_part.to_dict(),sort_keys=True, indent=4))
            return False
    return True
Exemple #7
0
def addDecay():
    """Adds POST data to new_physics collection, displays a thank you message"""
    request.get_data()
    
    document = {"type": "decay", "parent": "", "childs": [], "source": "", "comment": "", "br_frac": "", "status":"pending"}

    document["parent"] = request.form["parent"]
    document["source"] = request.form["decay_source"]
    document["comment"] = request.form["decay_comment"]
    document["br_frac"] = request.form["branching_fraction"]

    for i in request.form:
        if "child" in i:
            document["childs"].append(request.form[i])

    p_list = []
    for p in Particle.objects():
        p_list.append(p.to_dict()["name"])

    if document["parent"] not in p_list:
        return render_template("physics-not-added.html", reason = "Parent particle is unknown. Add it to the db or use drop-down menu")

    for d in document["childs"]:
        if d not in p_list:
            return render_template("physics-not-added.html", reason = "One of the child ("+d+") particles is unknown. Add it to the db or use drop-down menu")

    try:
        b = float(document["br_frac"])
        if (b>1) or (b<0):
            return render_template("physics-not-added.html", reason = "Branching fraction should be in range (0, 1)")
    except:
        return render_template("physics-not-added.html", reason = "Branching fraction should be a number in range (0, 1)")

    new_physics.insert_one(document)

    return render_template("physics-added.html")
Exemple #8
0
def howtosearch():
    p_list = []
    for p in Particle.objects():
        p_list.append(p.to_print())
    return render_template('HowToSearch.html', p_list = p_list)
Exemple #9
0
def add_physics():
    p_list = []
    for p in Particle.objects():
        p_list.append(p.to_print())
    return render_template('AddPhysics.html', p_list = p_list)
Exemple #10
0
from mongoengine import *
import json
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from parrticleparser.particle_model import Particle
particles = {}
for part in Particle.objects():
    particles[part.name]=part.to_dict()
from config import db_name
from config import br_cutoff, max_decay_chain
from parrticleparser.nice_name import nice_name

def order_particles(p_list):
    DATA=[]
    for p in p_list:
        DATA.append((p, particles[p]['mass'], particles[p]['charge']))
    DATA.sort(key=lambda row:row[2], reverse=True)
    DATA.sort(key=lambda row: row[1], reverse=True)
    o_list=[]
    for d in DATA:
        o_list.append(d[0])
    return o_list


class Decay(Document):

    parent = StringField(required = True)
    childs = ListField(StringField(),required = True)
    nice_decay = StringField(default = "", unique = True)
    branching = FloatField(required = True)
Exemple #11
0
                            mass = mass,
                            alias = antiparticle_alias,
                            antiparticle = name)
        try: 
            db_part.save()
        except:
            print("Failed to save particle:")
            print(json.dumps(db_part.to_dict(),sort_keys=True, indent=4))
            return False
    return True


if __name__ == '__main__':
    print("Example of adding particle to DB")
    print("We will add particle 'Delta-'")
    for p in Particle.objects(name = 'Delta-'):
        p.printparticle()    
    print("First, let's remove if from DB together with its CC")
    Particle.objects(name = 'Delta-').delete()
    Particle.objects(name = 'Delta~+').delete()
    print("Ans let's check if it is deleted:")
    for p in Particle.objects(name__in = ['Delta-','Delta~+']):
        p.printparticle()
    print("Now let's add it:")
    save_particle_to_db(
    name = "Delta-",
    charge = -1.0,
    mass = 1232.0,
    antiparticle = "Delta~+")
    print("And let's check if Delta- is here:")
    for p in Particle.objects(name = 'Delta-'):