def load_centers(iterable):  
    dict_ = CIDict()
    for row in iterable:
        if row[0] != '':
            dict_.update({row[0]:row[1]})
    for key, value in dict_.items():
        # Turns '(1,2,3)' etc, that is, textual representations of vectors,
        # into Vector objects. Will cut off the last digit of the third
        # componant, but I don't care because the third componant will
        # always be 0.0
        dict_[key] = np.array([float(y[:-1]) for y in value[1:].split()])
    return dict_
def moments(path, selections, centers):
    with open('published params.csv', 'rb') as f:
        reader = csv.reader(f)
        new_calc = ezb.Calculator(reader, normalize = False)

    moments = CIDict()
    for name in structures.keys():
        if name.upper() == '1QD5':
            continue

        moments.update({name:
                        ezb.moment(structures[name], selections[name],
                                   centers[name], new_calc,
                                   paramless_option = '0',
                                   old_style_gly = True) })

        with open(path, 'wb') as f:
            target = csv.writer(f)
            for name, moment in moments.items():
                row = [name.upper()] + [str(component) for component in moment]
                target.writerow(row)
def selections_by_index(iterable):
    selections = CIDict()
    test_sequences = CIDict()
    for line in iterable:
        selections.update({line[0]: [int(x) for x in line[2:]]})
        test_sequences.update({line[0]: line[1]})
    return selections, test_sequences
def selections_by_resi(iterable):
    selections = CIDict()
    for line in iterable:
        selections.update({line[0]: [int(x) for x in line[1:]]})
    return selections
with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    structures = [(name, parser.get_structure(name, path)) \
                  for name, path in structure_files.items()]
    structures = CIDict(structures)

with open('cored 1 selections with 1qd5.csv', 'rb') as f:
    reader = csv.reader(f)
    inclusive_selections = ezb.selections_by_resi(reader)
    
with open('beta_selections.csv', 'rb') as f:
    reader = csv.reader(f)
    beta_selections = ezb.selections_by_resi(reader)

exclusive_selections = CIDict()
    
for name, selection in beta_selections.items():
   exclusive_selections.update(((name, list(set(selection).intersection( 
                                      set(inclusive_selections[name])))),))
    

with open('cored 1 centers with 1qd5.csv', 'rb') as f:
    reader = csv.reader(f)
    inc_centers = ezb.load_centers(reader)

with open('exc centers.csv', 'rb') as f:
    exc_centers = ezb.load_centers(csv.reader(f))
    
def moments(path, selections, centers):
    with open('published params.csv', 'rb') as f:
# or thousands of warnings when loading them. The following code
# suppresses warnings
with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    structures = [(name, parser.get_structure(name, path)) \
                  for name, path in structure_files.items()]
    structures = CIDict(structures)


# Load the selections that should have been used

with open('exc centers/exc selections.csv', 'rb') as f:
    reader = csv.reader(f)
    beta_selections = ezb.selections_by_resi(reader)

right_selections = CIDict()
    
for name, selection in beta_selections.items():
   right_selections.update(((name, selection),))

with open('exc centers.csv', 'rb') as f:
    exc_centers = ezb.load_centers(csv.reader(f))
    
def moments(path, selections, centers):
    with open('published params.csv', 'rb') as f:
        reader = csv.reader(f)
        new_calc = ezb.Calculator(reader, normalize = True)

    moments = CIDict()
    for name in structures.keys():
        if name.upper() == '1QD5':
with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    structures = [(name, parser.get_structure(name, path)) \
                  for name, path in structure_files.items()]
    structures = CIDict(structures)

with open('cored 1 selections with 1qd5.csv', 'rb') as f:
    reader = csv.reader(f)
    inclusive_selections = ezb.selections_by_resi(reader)
    
with open('beta_selections.csv', 'rb') as f:
    reader = csv.reader(f)
    beta_selections = ezb.selections_by_resi(reader)

exclusive_selections = CIDict()
    
for name, selection in beta_selections.items():
   exclusive_selections.update(((name, list(set(selection).intersection( 
                                      set(inclusive_selections[name])))),))
    

with open('cored 1 centers with 1qd5.csv', 'rb') as f:
    reader = csv.reader(f)
    inc_centers = ezb.load_centers(reader)

with open('exc centers.csv', 'rb') as f:
    exc_centers = ezb.load_centers(csv.reader(f))
    
def moments(path, selections, centers):
    with open('published params.csv', 'rb') as f: