# Copyright 2021 AlQuraishi Laboratory
# Dingquan Yu @ EMBL-Hamburg Kosinski group
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path
import shutil
import pickle
import torch
import torch.nn as nn
import numpy as np
from functools import partial
import unittest
from openfold.config import model_config
from openfold.data.data_modules import OpenFoldDataModule
import logging
logger = logging.getLogger(__name__)
import os

class TestMultimerDataModule(unittest.TestCase):
    def setUp(self):
        """
        Set up model config

        use model_1_multimer_v3 for now
        """
        self.config = model_config(
        "model_1_multimer_v3", 
        train=True, 
        low_prec=True)
        self.data_module = OpenFoldDataModule(
        config=self.config.data, 
        batch_seed=42,
        template_mmcif_dir = "/g/alphafold/AlphaFold_DBs/2.3.0/pdb_mmcif/mmcif_files/",
        template_release_dates_cache_path=os.path.join(os.getcwd(),"tests/test_data/mmcif_cache.json"),
        max_template_date="2500-01-01",
        train_data_dir=os.path.join(os.getcwd(),"tests/test_data/mmcifs"),
        val_data_dir=os.path.join(os.getcwd(),"tests/test_data/mmcifs"),
        val_alignment_dir=os.path.join(os.getcwd(),"tests/test_data/alignments/validation"),
        train_alignment_dir=os.path.join(os.getcwd(),"tests/test_data/alignments/train"),
        kalign_binary_path=shutil.which('kalign'),
        train_chain_data_cache_path=os.path.join(os.getcwd(),"tests/test_data/train_chain_data_cache.json")
    )
        
    def testPrepareData(self):
        self.data_module.prepare_data()
        self.data_module.setup()