Code Duplication    Length = 39-57 lines in 2 locations

rna_tools/tools/PyMOL4RNA/PyMOL4RNA.py 2 locations

@@ 546-602 (lines=57) @@
543
    color_by_text(txt)
544
545
546
def color_obj(rainbow=0):
547
548
        """
549
        stolen from :)
550
AUTHOR
551
        Gareth Stockwell
552
553
USAGE
554
        color_obj(rainbow=0)
555
556
        This function colours each object currently in the PyMOL heirarchy
557
        with a different colour.  Colours used are either the 22 named
558
        colours used by PyMOL (in which case the 23rd object, if it exists,
559
        gets the same colour as the first), or are the colours of the rainbow
560
561
        """
562
563
        # Process arguments
564
        rainbow = int(rainbow)
565
566
        # Get names of all PyMOL objects
567
        obj_list = cmd.get_names('objects')
568
569
        if rainbow:
570
571
           print("\nColouring objects as rainbow\n")
572
573
           nobj = len(obj_list)
574
575
           # Create colours starting at blue(240) to red(0), using intervals
576
           # of 240/(nobj-1)
577
           for j in range(nobj):
578
              hsv = (240-j*240/(nobj-1), 1, 1)
579
              # Convert to RGB
580
              rgb = hsv_to_rgb(hsv)
581
              # Define the new colour
582
              cmd.set_color("col" + str(j), rgb)
583
              print(obj_list[j], rgb)
584
              # Colour the object
585
              cmd.color("col" + str(j), obj_list[j])
586
587
        else:
588
           # List of available colours
589
           colours = ['red', 'green', 'blue', 'yellow', 'violet', 'cyan',    \
590
           'salmon', 'lime', 'pink', 'slate', 'magenta', 'orange', 'marine', \
591
           'olive', 'purple', 'teal', 'forest', 'firebrick', 'chocolate',    \
592
           'wheat', 'white', 'grey' ]
593
           ncolours = len(colours)
594
595
           # Loop over objects
596
           i = 0
597
           for obj in obj_list:
598
              print("  ", obj, colours[i])
599
              cmd.color(colours[i], obj)
600
              i = i+1
601
              if(i == ncolours):
602
                 i = 0
603
604
605
def names():
@@ 612-650 (lines=39) @@
609
        print(o)
610
611
612
def color_rbw(rainbow=0):
613
        """
614
        similar to color_obj() but this time colors every obect as rainbow
615
        """
616
        rainbow = int(rainbow)
617
618
        # Get names of all PyMOL objects
619
        obj_list = cmd.get_names('objects')
620
621
        if rainbow:
622
623
           print("\nColouring objects as rainbow\n")
624
625
           nobj = len(obj_list)
626
627
           # Create colours starting at blue(240) to red(0), using intervals
628
           # of 240/(nobj-1)
629
           for j in range(nobj):
630
              hsv = (240-j*240/(nobj-1), 1, 1)
631
              # Convert to RGB
632
              rgb = hsv_to_rgb(hsv)
633
              # Define the new colour
634
              cmd.set_color("col" + str(j), rgb)
635
              print(obj_list[j], rgb)
636
              # Colour the object
637
              cmd.color("col" + str(j), obj_list[j])
638
        else:
639
           colours = ['rainbow']
640
           ncolours = len(colours)
641
642
           # Loop over objects
643
           i = 0
644
           for obj in obj_list:
645
              print("  ", obj, colours[i])
646
              cmd.spectrum('count', colours[i], obj)
647
#              cmd.color(colours[i], obj)
648
              i = i+1
649
              if(i == ncolours):
650
                 i = 0
651
652
def ino():
653
    """Sphare and yellow inorganic, such us Mg.