from Bio.PDB import PDBParser
from biodata import file_dict
import ezb

structure_files = file_dict('structures with 1qd5', ['aligned_(.*).pdb'])
parser = PDBParser()

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)
# Daniel's aligned pdb files are missing b factors, and perhaps 
# some other information, which causes Biopython to give hundreds
# 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()