60
60
""" a class for invalid Model """
62
62
last_model_path =''
63
def find_ufo_path(model_name):
63
def find_ufo_path(model_name, web_search=True):
64
64
""" find the path to a model """
66
66
global last_model_path
68
68
# Check for a valid directory
69
if model_name.startswith('./') and os.path.isdir(model_name):
69
if model_name.startswith(('./','../')) and os.path.isdir(model_name):
71
71
elif os.path.isdir(os.path.join(MG5DIR, 'models', model_name)):
72
72
return os.path.join(MG5DIR, 'models', model_name)
80
80
if os.path.isdir(model_name):
81
81
logger.warning('No model %s found in default path. Did you mean \'import model ./%s\'',
82
82
model_name, model_name)
83
raise UFOImportError("Path %s is not a valid pathname" % model_name)
83
if os.path.sep in model_name:
84
raise UFOImportError("Path %s is not a valid pathname" % model_name)
85
elif web_search and '-' not in model_name:
86
found = import_model_from_db(model_name)
88
return find_ufo_path(model_name, web_search=False)
90
raise UFOImportError("Path %s is not a valid pathname" % model_name)
85
92
raise UFOImportError("Path %s is not a valid pathname" % model_name)
94
raise UFOImportError("Path %s is not a valid pathname" % model_name)
99
"""return the file with the online model database"""
101
data_path = ['http://madgraph.phys.ucl.ac.be/models_db.dat',
102
'http://madgraph.physics.illinois.edu/models_db.dat']
105
r = random.randint(0,1)
109
cluster_path = data_path[index]
111
data = urllib.urlopen(cluster_path)
116
raise MadGraph5Error, '''Model not found locally and Impossible to connect any of us servers.
117
Please check your internet connection or retry later'''
120
def import_model_from_db(model_name):
121
""" import the model with a given name """
127
if model_name == split[0]:
131
logger.debug('no model with that name found online')
134
#get target directory
135
# 1. PYTHONPATH containing UFO
136
# 2. models directory
138
if 'PYTHONPATH' in os.environ:
139
for directory in os.environ['PYTHONPATH'].split(':'):
140
if 'UFO' in os.path.basename(directory) and os.path.exists(directory):
143
target = pjoin(MG5DIR, 'models')
145
os.remove(pjoin(target, 'tmp.tgz'))
148
logger.info("download model from %s to the following directory: %s", link, target, '$MG:color:BLACK')
149
if sys.platform == "darwin":
150
misc.call(['curl', link, '-otmp.tgz'], cwd=target)
152
misc.call(['wget', link, '--output-document=tmp.tgz'], cwd=target)
156
if link.endswith(('.tgz','.tar.gz')):
158
proc = misc.call('tar -xzpvf tmp.tgz', shell=True, cwd=target)#, stdout=devnull, stderr=devnull)
159
if proc: raise Exception
161
proc = misc.call('tar -xpvf tmp.tgz', shell=True, cwd=target)#, stdout=devnull, stderr=devnull)
163
if link.endswith(('.zip')):
165
proc = misc.call('unzip tmp.tgz', shell=True, cwd=target)#, stdout=devnull, stderr=devnull)
166
if proc: raise Exception
168
proc = misc.call('tar -xzpvf tmp.tgz', shell=True, cwd=target)#, stdout=devnull, stderr=devnull)
170
raise Exception, "Impossible to unpack the model. Please install it manually"
90
173
def import_model(model_name, decay=False, restrict=True, prefix='mdl_',
91
174
complex_mass_scheme = None):
92
175
""" a practical and efficient way to import a model"""
96
179
model_path = find_ufo_path(model_name)
97
180
except UFOImportError:
98
181
if '-' not in model_name:
182
if model_name == "mssm":
183
logger.error("mssm model has been replaced by MSSM_SLHA2 model.\n The new model require SLHA2 format. You can use the \"update to_slha2\" command to convert your slha1 param_card.\n That option is available at the time of the edition of the cards.")
100
185
split = model_name.split('-')
101
186
model_name = '-'.join([text for text in split[:-1]])
102
model_path = find_ufo_path(model_name)
188
model_path = find_ufo_path(model_name)
189
except UFOImportError:
190
if model_name == "mssm":
191
logger.error("mssm model has been replaced by MSSM_SLHA2 model.\n The new model require SLHA2 format. You can use the \"update to_slha2\" command to convert your slha1 param_card.\n That option is available at the time of the edition of the cards.")
103
193
restrict_name = split[-1]
105
195
restrict_file = os.path.join(model_path, 'restrict_%s.dat'% restrict_name)
327
417
def __init__(self, model, auto=False):
328
418
""" initialize empty list for particles/interactions """
420
if hasattr(model, '__arxiv__'):
421
logger.info('Please cite %s when using this model', model.__arxiv__, '$MG:color:BLACK')
330
423
self.particles = base_objects.ParticleList()
331
424
self.interactions = base_objects.InteractionList()
332
425
self.wavefunction_CT_couplings = []