Package madgraph :: Package loop :: Module MadLoopBannerStyles
[hide private]
[frames] | no frames]

Source Code for Module madgraph.loop.MadLoopBannerStyles

  1  ################################################################################ 
  2  # 
  3  # Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors 
  4  # 
  5  # This file is a part of the MadGraph5_aMC@NLO project, an application which  
  6  # automatically generates Feynman diagrams and matrix elements for arbitrary 
  7  # high-energy processes in the Standard Model and beyond. 
  8  # 
  9  # It is subject to the MadGraph5_aMC@NLO license which should accompany this  
 10  # distribution. 
 11  # 
 12  # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch 
 13  # 
 14  ################################################################################ 
 15   
 16  import random 
 17  if __name__=='__main__': 
 18      # Make sure paths are accessible 
 19      import os 
 20      import sys 
 21      root_path = os.path.split(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))[0] 
 22      sys.path.insert(0, root_path) 
 23   
 24  import madgraph.various.misc as misc 
 25  from madgraph import MadGraph5Error 
26 27 #=============================================================================== 28 # MadLoopBannerStyles 29 #=============================================================================== 30 -class MadLoopBannerStyles(object):
31 """ A container class to specify all banner styles. """ 32 # a dictionary contaning all banner styles 33 ordered_style_keys = ['classic','classic2','classic3','big','funky', 34 'curly','bubbles','mario','wiggly', 35 'printed','fast','isometric'] 36 styles = {} 37 styles['classic'] = \ 38 r""" 39 __ __ _ _ 40 | \/ | | | | 41 | \ / | __ _ __| | | ___ ___ _ __ 42 | |\/| |/ _` |/ _` | | / _ \ / _ \| '_ \ 43 | | | | (_| | (_| | |___| (_) | (_) | |_) | 44 |_| |_|\__,_|\__,_|______\___/ \___/| .__/ 45 | | 46 |_| 47 %(version)s 48 %(ref)s 49 """ 50 51 styles['classic2'] = \ 52 r""" 53 ,, 54 `7MMM. ,MMF' `7MM `7MMF' 55 MMMb dPMM MM MM 56 M YM ,M MM ,6"Yb. ,M""bMM MM ,pW"Wq. ,pW"Wq.`7MMpdMAo. 57 M Mb M' MM 8) MM ,AP MM MM 6W' `Wb 6W' `Wb MM `Wb 58 M YM.P' MM ,pm9MM 8MI MM MM , 8M M8 8M M8 MM M8 59 M `YM' MM 8M MM `Mb MM MM ,M YA. ,A9 YA. ,A9 MM ,AP 60 .JML. `' .JMML.`Moo9^Yo.`Wbmd"MML..JMMmmmmMMM `Ybmd9' `Ybmd9' MMbmmd' 61 MM 62 .JMML. 63 %(versionref)s 64 """ 65 66 styles['classic3'] = \ 67 r""" 68 __ __ _ _ 69 | \/ | __ _ __| | | ___ ___ _ __ 70 | |\/| |/ _` |/ _` | | / _ \ / _ \| '_ \ 71 | | | | (_| | (_| | |__| (_) | (_) | |_) | 72 |_| |_|\__,_|\__,_|_____\___/ \___/| .__/ 73 |_| 74 75 %(version)s 76 %(ref)s 77 """ 78 79 styles['big'] = \ 80 r""" 81 88b d88 88 88 82 888b d888 88 88 83 88`8b d8'88 88 88 84 88 `8b d8' 88 ,adPPYYba, ,adPPYb,88 88 ,adPPYba, ,adPPYba, 8b,dPPYba, 85 88 `8b d8' 88 "" `Y8 a8" `Y88 88 a8" "8a a8" "8a 88P' "8a 86 88 `8b d8' 88 ,adPPPPP88 8b 88 88 8b d8 8b d8 88 d8 87 88 `888' 88 88, ,88 "8a, ,d88 88 "8a, ,a8" "8a, ,a8" 88b, ,a8" 88 88 `8' 88 `"8bbdP"Y8 `"8bbdP"Y8 88888888888 `"YbbdP"' `"YbbdP"' 88`YbbdP"' 89 88 90 88 91 %(versionref)s 92 """ 93 94 styles['funky'] = \ 95 r""" 96 .-'''-. .-'''-. 97 _______ .---. ' _ \ ' _ \ 98 __ __ ___ \ ___ `'. | | / /` '. \ / /` '. \_________ _...._ 99 | |/ `.' `. ' |--.\ \ | |. | \ ' . | \ '\ |.' '-. 100 | .-. .-. ' | | \ ' | || ' | '| ' | '\ .'```'. '. 101 | | | | | | __ | | | '| |\ \ / / \ \ / / \ | \ \ 102 | | | | | | .:--.'. | | | || | `. ` ..' / `. ` ..' / | | | | 103 | | | | | |/ | \ | | | ' .'| | '-...-'` '-...-'` | \ / ; 104 | | | | | |`" __ | | | |___.' /' | | | |\`----' .' 105 |__| |__| |__| .'.''| | /_______.'/ | | | | '-....-'` 106 / / | |_\_______|/ '---' .' '. 107 \ \._,\ '/ '-----------' 108 `--' `" 109 110 111 %(versionref)s 112 """ 113 114 styles['curly'] = \ 115 r""" 116 __ __) _ 117 (, /| /| /) ___/__) 118 / | / | _ _(/ (, / ________ 119 ) / |/ |_(_(_(_(_ / (_)(_) /_)_ 120 (_/ ' (_____ .-/ 121 )(_/ 122 123 %(version)s 124 %(ref)s 125 """ 126 127 128 styles['keyboard'] = \ 129 r""" 130 ____ ____ ____ ____ ____ ____ ____ 131 ||M |||a |||d |||L |||o |||o |||p || 132 ||__|||__|||__|||__|||__|||__|||__|| 133 |/__\|/__\|/__\|/__\|/__\|/__\|/__\| 134 135 %(version)s 136 %(ref)s 137 """ 138 139 styles['bubbles'] = \ 140 r""" 141 Oo oO o o 142 O O o o O O 143 o o O O o o 144 O Oo O o o 145 O o .oOoO' .oOoO O .oOo. .oOo. .oOo. 146 o O O o o O O O o O o O o 147 o O o O O o o . o O o O o O 148 O o `OoO'o `OoO'o OOoOooO `OoO' `OoO' oOoO' 149 O 150 o' 151 %(version)s 152 %(ref)s 153 """ 154 155 styles['mario'] = \ 156 r""" 157 _ __ 158 /\/\ __ _ __| | / / ___ ___ _ __ 159 / \ / _` |/ _` |/ / / _ \ / _ \| '_ \ 160 / /\/\ \ (_| | (_| / /__| (_) | (_) | |_) | 161 \/ \/\__,_|\__,_\____/\___/ \___/| .__/ 162 |_| 163 %(version)s 164 %(ref)s 165 """ 166 167 styles['wiggly'] = \ 168 r""" 169 __ __ ____ ______ _____ ____ ____ _____ 170 \ \ / / ( ) (_ __ \ (_ _) / __ \ / __ \ ( __ \ 171 () \/ () / /\ \ ) ) \ \ | | / / \ \ / / \ \ ) )_) ) 172 / _ _ \ ( (__) ) ( ( ) ) | | ( () () ) ( () () ) ( ___/ 173 / / \/ \ \ ) ( ) ) ) ) | | __ ( () () ) ( () () ) ) ) 174 /_/ \_\ / /\ \ / /__/ / __| |___) ) \ \__/ / \ \__/ / ( ( 175 (/ \) /__( )__\ (______/ \________/ \____/ \____/ /__\ 176 177 %(versionref)s 178 """ 179 180 styles['printed'] = \ 181 r""" 182 __/\\\\____________/\\\\________________________/\\\___/\\\_______________________________________________________ 183 _\/\\\\\\________/\\\\\\_______________________\/\\\__\/\\\_______________________________________________________ 184 _\/\\\//\\\____/\\\//\\\_______________________\/\\\__\/\\\___________________________________________/\\\\\\\\\__ 185 _\/\\\\///\\\/\\\/_\/\\\__/\\\\\\\\\___________\/\\\__\/\\\_________________/\\\\\________/\\\\\_____/\\\/////\\\_ 186 _\/\\\__\///\\\/___\/\\\_\////////\\\_____/\\\\\\\\\__\/\\\_______________/\\\///\\\____/\\\///\\\__\/\\\\\\\\\\__ 187 _\/\\\____\///_____\/\\\___/\\\\\\\\\\___/\\\////\\\__\/\\\______________/\\\__\//\\\__/\\\__\//\\\_\/\\\//////___ 188 _\/\\\_____________\/\\\__/\\\/////\\\__\/\\\__\/\\\__\/\\\_____________\//\\\__/\\\__\//\\\__/\\\__\/\\\_________ 189 _\/\\\_____________\/\\\_\//\\\\\\\\/\\_\//\\\\\\\/\\_\/\\\\\\\\\\\\\\\__\///\\\\\/____\///\\\\\/___\/\\\_________ 190 _\///______________\///___\////////\//___\///////\//__\///////////////_____\/////________\/////_____\///__________ 191 192 %(versionref)s 193 """ 194 195 styles['fast'] = \ 196 r""" 197 __ ___ ____ 198 / |/ /___ _____/ / / ____ ____ ____ 199 / /|_/ / __ `/ __ / / / __ \/ __ \/ __ \ 200 / / / / /_/ / /_/ / /___/ /_/ / /_/ / /_/ / 201 /_/ /_/\__,_/\__,_/_____/\____/\____/ .___/ 202 /_/ 203 %(version)s 204 %(ref)s 205 """ 206 207 styles['isometric'] = \ 208 r""" 209 ___ ___ _____ ___ ___ ___ 210 /__/\ / /\ / /::\ / /\ / /\ / /\ 211 | |::\ / /::\ / /:/\:\ / /::\ / /::\ / /::\ 212 | |:|:\ / /:/\:\ / /:/ \:\ ___ ___ / /:/\:\ / /:/\:\ / /:/\:\ 213 __|__|:|\:\ / /:/~/::\ /__/:/ \__\:| /__/\ / /\ / /:/ \:\ / /:/ \:\ / /:/~/:/ 214 /__/::::| \:\ /__/:/ /:/\:\ \ \:\ / /:/ \ \:\ / /:/ /__/:/ \__\:\ /__/:/ \__\:\ /__/:/ /:/ 215 \ \:\~~\__\/ \ \:\/:/__\/ \ \:\ /:/ \ \:\ /:/ \ \:\ / /:/ \ \:\ / /:/ \ \:\/:/ 216 \ \:\ \ \::/ \ \:\/:/ \ \:\/:/ \ \:\ /:/ \ \:\ /:/ \ \::/ 217 \ \:\ \ \:\ \ \::/ \ \::/ \ \:\/:/ \ \:\/:/ \ \:\ 218 \ \:\ \ \:\ \__\/ \__\/ \ \::/ \ \::/ \ \:\ 219 \__\/ \__\/ \__\/ \__\/ \__\/ 220 221 %(versionref)s 222 """ 223 224 @classmethod
225 - def get_raw_banner(cls,style):
226 if style.lower()=='random': 227 chosen = random.choice(cls.get_style_keys()) 228 return cls.styles[chosen] 229 else: 230 return cls.styles[style]
231 232 @classmethod
233 - def get_style_keys(cls):
234 return cls.ordered_style_keys
235 236 @classmethod
237 - def get_MadLoop_Banner(cls, style='classic', color='blue', 238 top_frame_char = '=', bottom_frame_char = '=', 239 left_frame_char = '{',right_frame_char = '}', 240 print_frame=True, side_margin = 7, up_margin = 1):
241 """ Writes out MadLoop banner.""" 242 243 colors = {'black':30,'red':31,'green':32,'yellow':33, 244 'blue':34,'magenta':35,'cyan':36,'lightred':91,'lightgreen':92, 245 'lightyellow':93,'lightblue':94,'lightmagenta':95,'lightcyan':96, 246 'white':97,'none':-1} 247 248 if style.lower()=='random': 249 color = random.choice(['blue','green','red']) 250 251 reference = "Ref: arXiv:1103.0621v2, arXiv:1405.0301" 252 version = "v%(version)s (%(date)s)"%misc.get_pkg_info() 253 versionref = "%s, %s"%(version,reference) 254 if style.lower() not in cls.get_style_keys()+['random']: 255 raise MadGraph5Error('Incorrect style in MadLoopBanner. Must be'+\ 256 ' one of the following: %s'%str(cls.get_style_keys()+['random'])) 257 258 if isinstance(color,int): 259 color_start ="char(27)//'[%im"%int 260 color_end = "char(27)//'[0m" 261 elif color.lower() in colors: 262 if color.lower()=='none': 263 color_start = "" 264 color_end = "" 265 else: 266 color_start ="char(27)//'[%im"%colors[color.lower()] 267 color_end = "char(27)//'[0m" 268 else: 269 raise MadGraph5Error('Incorrect color in MadLoopBanner. Must be and'+\ 270 ' intenger or one of the following: %s'%str(colors.keys())) 271 272 def format_banner(banner): 273 """ Format the raw banner text to give it a frame, colors and a 274 margin.""" 275 276 def fw(*args): 277 """Fortran write line""" 278 elems = [] 279 for arg in args: 280 if arg.startswith('char('): 281 elems.append("%s'"%arg) 282 continue 283 # Hard-set the single and double quotes in the text to 284 # make sure it is not processed by the FileWriter. 285 arg = arg.replace("'","'//char(39)//'") 286 arg = arg.replace('"',"'//char(34)//'") 287 if len(arg)>0: 288 elems.append("'%s'"%arg) 289 return "write(*,*) %s"%("//".join(elems))
290 291 banner_lines = banner.split('\n') 292 formatted_lines = [] 293 294 # Determine the target width 295 width = side_margin*2 + max(len(line) for line in banner_lines) 296 if print_frame: 297 width += 2 298 299 # Print the upper frame 300 if print_frame: 301 formatted_lines.append(fw(" %s "%(top_frame_char*(width-2)))) 302 303 # Print the upper margin 304 for i in range(up_margin): 305 formatted_lines.append(fw("%(lside)s%(width)s%(rside)s"% 306 {'lside':left_frame_char if print_frame else '', 307 'rside':right_frame_char if print_frame else '', 308 'width':' '*(width-2)})) 309 310 # Now print the banner 311 for line in banner_lines: 312 line_elements = [] 313 line_elements.append((left_frame_char if 314 print_frame else '')+' '*side_margin) 315 # Colorize the logo 316 line_elements.append(color_start) 317 # Make sure to write the reference in black 318 found = False 319 for tag in [versionref, reference, version]: 320 if tag in line: 321 line_elements.extend([line[:line.index(tag)], 322 color_end,tag,color_start, 323 line[line.index(tag)+len(tag):]+ 324 ' '*(width-2*(side_margin+1)-len(line))]) 325 found = True 326 break 327 if not found: 328 line_elements.append(line+ 329 ' '*(width-2*(side_margin+1)-len(line))) 330 line_elements.append(color_end) 331 line_elements.append(' '*side_margin+(right_frame_char 332 if print_frame else '')) 333 formatted_lines.append(fw(*line_elements)) 334 335 # Print the lower margin (of height equal to up margin) 336 for i in range(up_margin): 337 formatted_lines.append(fw("%(lside)s%(width)s%(rside)s"% 338 {'lside':left_frame_char if print_frame else '', 339 'rside':right_frame_char if print_frame else '', 340 'width':' '*(width-2)})) 341 342 # Print the lower frame 343 if print_frame: 344 formatted_lines.append(fw(" %s "%(bottom_frame_char*(width-2)))) 345 346 return '\n'.join(formatted_lines)
347 348 # Now we define the raw banner text for each style: 349 350 return format_banner( 351 cls.get_raw_banner(style.lower()) 352 %{'versionref':versionref, 'ref':reference, 'version':version}) 353 354 # Below we have a small standalone code to test the MadLoop Banner output 355 if __name__=='__main__': 356 import madgraph.iolibs.file_writers as writers 357 import os 358 import copy 359 pjoin = os.path.join 360 writer = writers.FortranWriter('test_ML_banner.f') 361 362 styles = copy.copy(MadLoopBannerStyles.get_style_keys()) 363 styles.append('random') 364 # Edit the line above and select here a subset of the available styles to 365 # show. Possibilities are: 366 # ['classic','classic2','classic3','big','funky', 367 # 'curly','keyboard','bubbles','mario','wiggly', 368 # 'printed','fast','isometric','random'] 369 # styles = ['funky'] 370 371 f_code = "" 372 for style in styles: 373 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s with default options.'\n"%style 374 f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style) 375 376 for style in styles: 377 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s in red.'\n"%style 378 f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style, color='red') 379 380 for style in styles: 381 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s in green.'\n"%style 382 f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style, color='green') 383 384 for style in styles: 385 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s without frame.'\n"%style 386 f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style, print_frame=False) 387 388 for style in styles: 389 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s with a different frame.'\n"%style 390 f_code += MadLoopBannerStyles.get_MadLoop_Banner( 391 side_margin=10, up_margin=3, 392 top_frame_char = '-', 393 bottom_frame_char = '-', 394 left_frame_char = '*', 395 right_frame_char = '*', 396 style=style) 397 398 writer.writelines("program testMLBanner\n%s\nend\n"%f_code) 399 writer.close() 400 # Now compile and run the code 401 if os.path.isfile(pjoin(os.getcwd(),'test_ML_banner')): 402 os.remove(pjoin(os.getcwd(),'test_ML_banner')) 403 misc.call('gfortran -o test_ML_banner test_ML_banner.f', 404 cwd=os.getcwd(),shell=True) 405 misc.call('./test_ML_banner',cwd=os.getcwd(),shell=True) 406