| @@ 790-846 (lines=57) @@ | ||
| 787 | color_by_text(txt) |
|
| 788 | ||
| 789 | ||
| 790 | def color_obj(rainbow=0): |
|
| 791 | ||
| 792 | """ |
|
| 793 | stolen from :) |
|
| 794 | AUTHOR |
|
| 795 | Gareth Stockwell |
|
| 796 | ||
| 797 | USAGE |
|
| 798 | color_obj(rainbow=0) |
|
| 799 | ||
| 800 | This function colours each object currently in the PyMOL heirarchy |
|
| 801 | with a different colour. Colours used are either the 22 named |
|
| 802 | colours used by PyMOL (in which case the 23rd object, if it exists, |
|
| 803 | gets the same colour as the first), or are the colours of the rainbow |
|
| 804 | ||
| 805 | """ |
|
| 806 | ||
| 807 | # Process arguments |
|
| 808 | rainbow = int(rainbow) |
|
| 809 | ||
| 810 | # Get names of all PyMOL objects |
|
| 811 | obj_list = cmd.get_names('objects') |
|
| 812 | ||
| 813 | if rainbow: |
|
| 814 | ||
| 815 | print("\nColouring objects as rainbow\n") |
|
| 816 | ||
| 817 | nobj = len(obj_list) |
|
| 818 | ||
| 819 | # Create colours starting at blue(240) to red(0), using intervals |
|
| 820 | # of 240/(nobj-1) |
|
| 821 | for j in range(nobj): |
|
| 822 | hsv = (240-j*240/(nobj-1), 1, 1) |
|
| 823 | # Convert to RGB |
|
| 824 | rgb = hsv_to_rgb(hsv) |
|
| 825 | # Define the new colour |
|
| 826 | cmd.set_color("col" + str(j), rgb) |
|
| 827 | print(obj_list[j], rgb) |
|
| 828 | # Colour the object |
|
| 829 | cmd.color("col" + str(j), obj_list[j]) |
|
| 830 | ||
| 831 | else: |
|
| 832 | # List of available colours |
|
| 833 | colours = ['red', 'green', 'blue', 'yellow', 'violet', 'cyan', \ |
|
| 834 | 'salmon', 'lime', 'pink', 'slate', 'magenta', 'orange', 'marine', \ |
|
| 835 | 'olive', 'purple', 'teal', 'forest', 'firebrick', 'chocolate', \ |
|
| 836 | 'wheat', 'white', 'grey' ] |
|
| 837 | ncolours = len(colours) |
|
| 838 | ||
| 839 | # Loop over objects |
|
| 840 | i = 0 |
|
| 841 | for obj in obj_list: |
|
| 842 | print(" ", obj, colours[i]) |
|
| 843 | cmd.color(colours[i], obj) |
|
| 844 | i = i+1 |
|
| 845 | if(i == ncolours): |
|
| 846 | i = 0 |
|
| 847 | ||
| 848 | ||
| 849 | def names(): |
|
| @@ 856-894 (lines=39) @@ | ||
| 853 | print(o) |
|
| 854 | ||
| 855 | ||
| 856 | def color_rbw(rainbow=0): |
|
| 857 | """ |
|
| 858 | similar to color_obj() but this time colors every obect as rainbow |
|
| 859 | """ |
|
| 860 | rainbow = int(rainbow) |
|
| 861 | ||
| 862 | # Get names of all PyMOL objects |
|
| 863 | obj_list = cmd.get_names('objects') |
|
| 864 | ||
| 865 | if rainbow: |
|
| 866 | ||
| 867 | print("\nColouring objects as rainbow\n") |
|
| 868 | ||
| 869 | nobj = len(obj_list) |
|
| 870 | ||
| 871 | # Create colours starting at blue(240) to red(0), using intervals |
|
| 872 | # of 240/(nobj-1) |
|
| 873 | for j in range(nobj): |
|
| 874 | hsv = (240-j*240/(nobj-1), 1, 1) |
|
| 875 | # Convert to RGB |
|
| 876 | rgb = hsv_to_rgb(hsv) |
|
| 877 | # Define the new colour |
|
| 878 | cmd.set_color("col" + str(j), rgb) |
|
| 879 | print(obj_list[j], rgb) |
|
| 880 | # Colour the object |
|
| 881 | cmd.color("col" + str(j), obj_list[j]) |
|
| 882 | else: |
|
| 883 | colours = ['rainbow'] |
|
| 884 | ncolours = len(colours) |
|
| 885 | ||
| 886 | # Loop over objects |
|
| 887 | i = 0 |
|
| 888 | for obj in obj_list: |
|
| 889 | print(" ", obj, colours[i]) |
|
| 890 | cmd.spectrum('count', colours[i], obj) |
|
| 891 | # cmd.color(colours[i], obj) |
|
| 892 | i = i+1 |
|
| 893 | if(i == ncolours): |
|
| 894 | i = 0 |
|
| 895 | ||
| 896 | ||
| 897 | def strip_selection_name(selection_name): |
|