Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 70 additions & 65 deletions Models/scripts/particle_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@

def create_entry(macro, particle_list):

'''Create the correct entry to add to particle_database.cpp. The
'''Create the correct entry to add to particle_database.cpp. The
argument "macro" should be one of the macros in particle_macros.hpp.'''
# Output to add to the particle database.

# Output to add to the particle database.
output = "\n "

for i in range(0, len(particle_list)):

entry = particle_list[i]

PDG = entry['PDG_context']

# Count how many particles appear in the PDG_context lists.
Expand Down Expand Up @@ -90,88 +90,93 @@ def create_entry(macro, particle_list):
print('Charge (x3) for particle {}').format(entry['name'])
print('is not an integer. Please check particle_database.yaml.')
sys.exit()
# Add the macro plus the particle name, plus the PDG-context pair.

# Add the macro plus the particle name, plus the PDG-context pair.
output += macro + '("{0}", {1}, {2}, {3}, {4})\n '.format(str(entry['name']), str(PDG).replace(']',')').replace('[','('), str(spinx2), str(chargex3), str(color))

# If the YAML file says there is a conjugate particle, add the name of it and the negative PDG-context pair
if 'conjugate' in entry:
if 'conjugate' in entry:
output += macro + '("{0}", {1}, {2}, {3}, {4})\n '.format(str(entry['conjugate']), str(PDGbar).replace(']',')').replace('[','('), str(spinx2), str(chargex3), str(color))

return output

def main(argv):

with open("./config/particle_database.yaml", "r") as f:

try:
data = yaml.safe_load(f)
except yaml.YAMLerror as exc:
print (exc)

# These correspond to the five macros in particle_macros.hpp.
SM_particles = data['StandardModel']['Particles'] # add_SM_particle
SM_sets = data['StandardModel']['Sets'] # add_SM_partcle_set
BSM_particles = data['OtherModels']['Particles'] # add_particle
BSM_sets = data['OtherModels']['Sets'] # add_particle_set
Generic = data['OtherModels']['Generic'] # add_generic_particle

towrite = """// GAMBIT: Global and Modular BSM Inference Tool

# Write header and open namespaces
now = datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
towrite = rf"""\
// GAMBIT: Global and Modular BSM Inference Tool
// *********************************************
/// \\file
///
/// Compile-time generation of particle
/// database.
///
/// This file was automatically generated by
/// particle_harvester.py. Do not modify.
///
/// Do not add to this if you want to add new
/// particles -- just add the particles to the
/// include/gambit/Models/particle_database.yaml
/// file, and be confident that the particle
/// harvester will add it to the database.
///
/// \\file
///
/// Compile-time generation of particle
/// database.
///
/// This file was automatically generated by
/// particle_harvester.py. Do not modify.
///
/// Do not add to this if you want to add new
/// particles -- just add the particles to the
/// include/gambit/Models/particle_database.yaml
/// file, and be confident that the particle
/// harvester will add it to the database.
///
/// *********************************************
///
/// Authors (add name and date if you modify):
///
/// \\author The GAMBIT Collaboration
/// \\date """+datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")+"""
///
///
/// Authors (add name and date if you modify):
///
/// \\author The GAMBIT Collaboration
/// \\date {now}
///
/// *********************************************

// Automatically-generated particle database.


#include \"gambit/Models/partmap.hpp\"
#include \"gambit/Models/particle_macros.hpp\"

namespace Gambit
{

namespace Models
{

void define_particles(partmap* particles)
{

// Automatically-generated particle database.


#include \"gambit/Models/partmap.hpp\"
#include \"gambit/Models/particle_macros.hpp\"

namespace Gambit
{{

namespace Models
{{

void define_particles(partmap* particles)
{{
"""
towrite += create_entry("add_SM_particle", SM_particles)

towrite += create_entry("add_SM_particle_set", SM_sets)

towrite += create_entry("add_particle", BSM_particles)

towrite += create_entry("add_particle_set", BSM_sets)

towrite += create_entry("add_generic_particle", Generic)

# Write footer, closing namespaces
towrite += rf"""
}}

}}

}}
"""
towrite+= create_entry("add_SM_particle", SM_particles)

towrite+= create_entry("add_SM_particle_set", SM_sets)

towrite+= create_entry("add_particle", BSM_particles)

towrite+= create_entry("add_particle_set", BSM_sets)

towrite+= create_entry("add_generic_particle", Generic)

towrite+=" \n\
} \n\
\n\
} \n\
\n\
} \n"


with open("./Models/src/particle_database.cpp","w") as f:
Expand Down
Loading
Loading