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)
97
def import_model_from_db(model_name):
99
data_path = ['http://madgraph.phys.ucl.ac.be/models_db.dat',
100
'http://madgraph.physics.illinois.edu/models_db.dat']
103
r = random.randint(0,1)
107
cluster_path = data_path[index]
109
data = urllib.urlopen(cluster_path)
114
raise MadGraph5Error, '''Model not found locally and Impossible to connect any of us servers.
115
Please check your internet connection or retry later'''
120
if model_name == split[0]:
124
logger.debug('no model with that name found online')
127
#get target directory
128
# 1. PYTHONPATH containing UFO
129
# 2. models directory
131
if 'PYTHONPATH' in os.environ:
132
for directory in os.environ['PYTHONPATH'].split(':'):
133
if 'UFO' in os.path.basename(directory) and os.path.exists(directory):
136
target = pjoin(MG5DIR, 'models')
138
os.remove(pjoin(target, 'tmp.tgz'))
141
logger.info("download model from %s to the following directory: %s", link, target, '$MG:color:BLACK')
142
if sys.platform == "darwin":
143
misc.call(['curl', link, '-otmp.tgz'], cwd=target)
145
misc.call(['wget', link, '--output-document=tmp.tgz'], cwd=target)
149
if link.endswith(('.tgz','.tar.gz')):
151
proc = misc.call('tar -xzpvf tmp.tgz', shell=True, cwd=target)#, stdout=devnull, stderr=devnull)
152
if proc: raise Exception
154
proc = misc.call('tar -xpvf tmp.tgz', shell=True, cwd=target)#, stdout=devnull, stderr=devnull)
156
if link.endswith(('.zip')):
158
proc = misc.call('unzip tmp.tgz', shell=True, cwd=target)#, stdout=devnull, stderr=devnull)
159
if proc: raise Exception
161
proc = misc.call('tar -xzpvf tmp.tgz', shell=True, cwd=target)#, stdout=devnull, stderr=devnull)
163
raise Exception, "Impossible to unpack the model. Please install it manually"
90
166
def import_model(model_name, decay=False, restrict=True, prefix='mdl_',
91
167
complex_mass_scheme = None):
92
168
""" a practical and efficient way to import a model"""