|
46 | 46 | from rmgpy.molecule.graph import Vertex, Edge, Graph |
47 | 47 | from rmgpy.molecule.fragment import CuttingLabel |
48 | 48 |
|
| 49 | +# helper functions |
| 50 | +# these were originall nested inside the indicated parent function, but when we upgraded to |
| 51 | +# Cython 3 this was no longer allowed - thus, they now live here. |
49 | 52 |
|
50 | | -################################################################################ |
| 53 | +# add_implicit_benzene |
| 54 | +def check_set(super_list, sub_list): |
| 55 | + """ |
| 56 | + Args: |
| 57 | + super_list: list to check if superset of partList |
| 58 | + sub_list: list to check if subset of superList |
| 59 | +
|
| 60 | + Returns: Boolean to see if super_list is a superset of sub_list |
| 61 | +
|
| 62 | + """ |
| 63 | + super_set = set(super_list) |
| 64 | + sub_set = set(sub_list) |
| 65 | + return super_set.issuperset(sub_set) |
| 66 | + |
| 67 | +def add_cb_atom_to_ring(ring, cb_atom): |
| 68 | + """ |
| 69 | + Every 'Cb' atom belongs in exactly one benzene ring. This function checks |
| 70 | + adds the cb_atom to the ring (in connectivity order) if the cb_atom is connected |
| 71 | + to any the last or first atom in the partial ring. |
| 72 | +
|
| 73 | + Args: |
| 74 | + ring: list of :class:GroupAtoms representing a partial ring to merge |
| 75 | + cb_atom: :class:GroupAtom with atomtype 'Cb' |
| 76 | +
|
| 77 | + Returns: If cb_atom connects to the beginning or end of ring, returns a |
| 78 | + new list of the merged ring, otherwise an empty list |
| 79 | +
|
| 80 | + """ |
| 81 | + |
| 82 | + merged_ring = [] |
| 83 | + # ring already complete |
| 84 | + if len(ring) == 6: return merged_ring |
| 85 | + for atom2, bond12 in cb_atom.bonds.items(): |
| 86 | + if bond12.is_benzene(): |
| 87 | + if atom2 is ring[-1]: |
| 88 | + merged_ring = ring + [cb_atom] |
| 89 | + elif atom2 is ring[0]: |
| 90 | + merged_ring = [cb_atom] + ring |
| 91 | + |
| 92 | + return merged_ring |
| 93 | + |
| 94 | +def merge_overlapping_benzene_rings(ring1, ring2, od): |
| 95 | + """ |
| 96 | + The input arguments of rings are always in the order that the atoms appear |
| 97 | + inside the ring. That is, each atom is connected to the ones adjacent on the |
| 98 | + list. |
| 99 | +
|
| 100 | + Args: |
| 101 | + ring1: list of :class:GroupAtoms representing first partial ring to merge |
| 102 | + ring2: list :class:GroupAtoms representing second partial ring to merge |
| 103 | + od: in for overlap distance |
| 104 | +
|
| 105 | + This function tries to see if the beginning or ends of each list have the |
| 106 | + same atom objects, i.e the two part rings should be merged together. |
| 107 | +
|
| 108 | + Returns: If rings are mergable, returns a new list of the merged ring, otherwise |
| 109 | + an empty list |
| 110 | +
|
| 111 | + """ |
| 112 | + new_ring = [] |
| 113 | + # ring already complete |
| 114 | + if len(ring1) == 6 or len(ring2) == 6: return new_ring |
| 115 | + |
| 116 | + # start of ring1 matches end of ring2 |
| 117 | + match_list1 = [x1 is x2 for x1, x2 in zip(ring1[-od:], ring2[:od])] |
| 118 | + # end of ring1 matches end of ring2 |
| 119 | + match_list2 = [x1 is x2 for x1, x2 in zip(ring1[-od:], ring2[:od - 1:-1])] |
| 120 | + # start of ring1 matches end of ring2 |
| 121 | + match_list3 = [x1 is x2 for x1, x2 in zip(ring1[:od], ring2[-od:])] |
| 122 | + # start of ring1 matches start of ring2 |
| 123 | + match_list4 = [x1 is x2 for x1, x2 in zip(ring1[:od], ring2[od::-1])] |
| 124 | + if False not in match_list1: |
| 125 | + new_ring = ring1 + ring2[od:] |
| 126 | + elif False not in match_list2: |
| 127 | + new_ring = ring1 + ring2[-od - 1::-1] |
| 128 | + elif False not in match_list3: |
| 129 | + new_ring = ring2[:-od] + ring1 |
| 130 | + elif False not in match_list4: |
| 131 | + new_ring = ring2[:od - 1:-1] + ring1 |
| 132 | + |
| 133 | + return new_ring |
51 | 134 |
|
52 | 135 | class GroupAtom(Vertex): |
53 | 136 | """ |
@@ -2531,89 +2614,6 @@ def add_implicit_benzene(self): |
2531 | 2614 | # Note that atomtypes like N5bd are mostly referred to as Cb in this code, |
2532 | 2615 | # which was first written for just carbon. |
2533 | 2616 |
|
2534 | | - # First define some helper functions |
2535 | | - def check_set(super_list, sub_list): |
2536 | | - """ |
2537 | | - Args: |
2538 | | - super_list: list to check if superset of partList |
2539 | | - sub_list: list to check if subset of superList |
2540 | | -
|
2541 | | - Returns: Boolean to see if super_list is a superset of sub_list |
2542 | | -
|
2543 | | - """ |
2544 | | - super_set = set(super_list) |
2545 | | - sub_set = set(sub_list) |
2546 | | - return super_set.issuperset(sub_set) |
2547 | | - |
2548 | | - def add_cb_atom_to_ring(ring, cb_atom): |
2549 | | - """ |
2550 | | - Every 'Cb' atom belongs in exactly one benzene ring. This function checks |
2551 | | - adds the cb_atom to the ring (in connectivity order) if the cb_atom is connected |
2552 | | - to any the last or first atom in the partial ring. |
2553 | | -
|
2554 | | - Args: |
2555 | | - ring: list of :class:GroupAtoms representing a partial ring to merge |
2556 | | - cb_atom: :class:GroupAtom with atomtype 'Cb' |
2557 | | -
|
2558 | | - Returns: If cb_atom connects to the beginning or end of ring, returns a |
2559 | | - new list of the merged ring, otherwise an empty list |
2560 | | -
|
2561 | | - """ |
2562 | | - |
2563 | | - merged_ring = [] |
2564 | | - # ring already complete |
2565 | | - if len(ring) == 6: return merged_ring |
2566 | | - for atom2, bond12 in cb_atom.bonds.items(): |
2567 | | - if bond12.is_benzene(): |
2568 | | - if atom2 is ring[-1]: |
2569 | | - merged_ring = ring + [cb_atom] |
2570 | | - elif atom2 is ring[0]: |
2571 | | - merged_ring = [cb_atom] + ring |
2572 | | - |
2573 | | - return merged_ring |
2574 | | - |
2575 | | - def merge_overlapping_benzene_rings(ring1, ring2, od): |
2576 | | - """ |
2577 | | - The input arguments of rings are always in the order that the atoms appear |
2578 | | - inside the ring. That is, each atom is connected to the ones adjacent on the |
2579 | | - list. |
2580 | | -
|
2581 | | - Args: |
2582 | | - ring1: list of :class:GroupAtoms representing first partial ring to merge |
2583 | | - ring2: list :class:GroupAtoms representing second partial ring to merge |
2584 | | - od: in for overlap distance |
2585 | | -
|
2586 | | - This function tries to see if the beginning or ends of each list have the |
2587 | | - same atom objects, i.e the two part rings should be merged together. |
2588 | | -
|
2589 | | - Returns: If rings are mergable, returns a new list of the merged ring, otherwise |
2590 | | - an empty list |
2591 | | -
|
2592 | | - """ |
2593 | | - new_ring = [] |
2594 | | - # ring already complete |
2595 | | - if len(ring1) == 6 or len(ring2) == 6: return new_ring |
2596 | | - |
2597 | | - # start of ring1 matches end of ring2 |
2598 | | - match_list1 = [x1 is x2 for x1, x2 in zip(ring1[-od:], ring2[:od])] |
2599 | | - # end of ring1 matches end of ring2 |
2600 | | - match_list2 = [x1 is x2 for x1, x2 in zip(ring1[-od:], ring2[:od - 1:-1])] |
2601 | | - # start of ring1 matches end of ring2 |
2602 | | - match_list3 = [x1 is x2 for x1, x2 in zip(ring1[:od], ring2[-od:])] |
2603 | | - # start of ring1 matches start of ring2 |
2604 | | - match_list4 = [x1 is x2 for x1, x2 in zip(ring1[:od], ring2[od::-1])] |
2605 | | - if False not in match_list1: |
2606 | | - new_ring = ring1 + ring2[od:] |
2607 | | - elif False not in match_list2: |
2608 | | - new_ring = ring1 + ring2[-od - 1::-1] |
2609 | | - elif False not in match_list3: |
2610 | | - new_ring = ring2[:-od] + ring1 |
2611 | | - elif False not in match_list4: |
2612 | | - new_ring = ring2[:od - 1:-1] + ring1 |
2613 | | - |
2614 | | - return new_ring |
2615 | | - |
2616 | | - ####################################################################################### |
2617 | 2617 | # start of main algorithm |
2618 | 2618 | copy_group = deepcopy(self) |
2619 | 2619 | """ |
|
0 commit comments