@@ -45,6 +45,8 @@ def _check_construction_table(construction_table):
45
45
if not reference .isin (c_table .index [:row ]).all ():
46
46
raise UndefinedCoordinateSystem (give_message (i = i ))
47
47
48
+
49
+
48
50
def _get_frag_constr_table (self , start_atom = None , predefined_table = None ,
49
51
use_lookup = None , bond_dict = None ):
50
52
"""Create a construction table for a Zmatrix.
@@ -74,43 +76,21 @@ def _get_frag_constr_table(self, start_atom=None, predefined_table=None,
74
76
if use_lookup is None :
75
77
use_lookup = settings ['defaults' ]['use_lookup' ]
76
78
77
- def modify_priority (bond_dict , user_defined ):
78
- def move_to_start (dct , key ):
79
- "Due to PY27 compatibility"
80
- keys = dct .keys ()
81
- if key in keys and key != keys [0 ]:
82
- root = dct ._OrderedDict__root
83
- first = root [1 ]
84
- link = dct ._OrderedDict__map [key ]
85
- link_prev , link_next , _ = link
86
- link_prev [1 ] = link_next
87
- link_next [0 ] = link_prev
88
- link [0 ] = root
89
- link [1 ] = first
90
- root [1 ] = first [0 ] = link
91
- else :
92
- raise KeyError
93
-
94
- for j in reversed (user_defined ):
95
- try :
96
- try :
97
- bond_dict .move_to_end (j , last = False )
98
- except AttributeError :
99
- # No move_to_end method in python 2.x
100
- move_to_start (bond_dict , j )
101
- except KeyError :
102
- pass
103
-
104
79
if start_atom is not None and predefined_table is not None :
105
80
raise IllegalArgumentCombination ('Either start_atom or '
106
81
'predefined_table has to be None' )
107
82
if bond_dict is None :
108
83
bond_dict = self ._give_val_sorted_bond_dict (use_lookup = use_lookup )
84
+
109
85
if predefined_table is not None :
110
86
self ._check_construction_table (predefined_table )
111
87
construction_table = predefined_table .copy ()
112
88
113
- if predefined_table is None :
89
+ i = construction_table .index [0 ]
90
+ order_of_def = list (construction_table .index )
91
+ user_defined = list (construction_table .index )
92
+ construction_table = construction_table .to_dict (orient = 'index' )
93
+ else :
114
94
if start_atom is None :
115
95
molecule = self .get_distance_to (self .get_centroid ())
116
96
i = molecule ['distance' ].idxmin ()
@@ -121,18 +101,13 @@ def move_to_start(dct, key):
121
101
construction_table = {i : {'b' : 'origin' ,
122
102
'a' : 'e_z' ,
123
103
'd' : 'e_x' }}
124
- else :
125
- i = construction_table .index [0 ]
126
- order_of_def = list (construction_table .index )
127
- user_defined = list (construction_table .index )
128
- construction_table = construction_table .to_dict (orient = 'index' )
129
104
130
105
visited = {i }
131
106
if len (self ) > 1 :
132
107
parent = {j : i for j in bond_dict [i ]}
133
108
work_bond_dict = OrderedDict (
134
109
[(j , bond_dict [j ] - visited ) for j in bond_dict [i ]])
135
- modify_priority (work_bond_dict , user_defined )
110
+ _modify_priority (work_bond_dict , user_defined )
136
111
else :
137
112
parent , work_bond_dict = {}, {}
138
113
@@ -181,7 +156,7 @@ def move_to_start(dct, key):
181
156
parent [j ] = i
182
157
183
158
work_bond_dict = new_work_bond_dict
184
- modify_priority (work_bond_dict , user_defined )
159
+ _modify_priority (work_bond_dict , user_defined )
185
160
output = pd .DataFrame .from_dict (construction_table , orient = 'index' )
186
161
output = output .loc [order_of_def , ['b' , 'a' , 'd' ]]
187
162
return output
@@ -746,3 +721,31 @@ def to_zmat(self, *args, **kwargs):
746
721
warnings .simplefilter ("always" )
747
722
warnings .warn (message , DeprecationWarning )
748
723
return self .get_zmat (* args , ** kwargs )
724
+
725
+
726
+ def _modify_priority (bond_dict , user_defined ):
727
+ def move_to_start (dct , key ):
728
+ "Due to PY27 compatibility"
729
+ keys = dct .keys ()
730
+ if key in keys and key != keys [0 ]:
731
+ root = dct ._OrderedDict__root
732
+ first = root [1 ]
733
+ link = dct ._OrderedDict__map [key ]
734
+ link_prev , link_next , _ = link
735
+ link_prev [1 ] = link_next
736
+ link_next [0 ] = link_prev
737
+ link [0 ] = root
738
+ link [1 ] = first
739
+ root [1 ] = first [0 ] = link
740
+ else :
741
+ raise KeyError
742
+
743
+ for j in reversed (user_defined ):
744
+ try :
745
+ try :
746
+ bond_dict .move_to_end (j , last = False )
747
+ except AttributeError :
748
+ # No move_to_end method in python 2.x
749
+ move_to_start (bond_dict , j )
750
+ except KeyError :
751
+ pass
0 commit comments