Esempio n. 1
0
def test_map_bmimbf4(tmp_path: Path):
    """
    Tests the map process for the BMIM BF4 system.
    """
    sys = System(BMIMBF4_SYS, BMIM_CG_ITP, BF4_CG_ITP)
    bmim = System(BMIM_AA_GRO, BMIM_AA_ITP)[0]
    bf4 = System(BF4_AA_GRO, BF4_AA_ITP)[0]
    man = Manager(sys)
    man.add_end_molecule(bmim)
    man.add_end_molecule(bf4)
    man.align_molecules()
    man.calculate_exchange_maps()

    subdir = tmp_path / "complete_alg_test"
    subdir.mkdir()
    fname = str(subdir / "system_CG_mapped_test.gro")

    man.extrapolate_system(fname)

    sys_end = System(fname, BMIM_AA_ITP, BF4_AA_ITP)

    # Tolerance in comparison
    poss = sys[0].atoms_positions
    tol = 0.1 * np.linalg.norm(np.max(poss, 0) + np.min(poss, 0))

    assert len(sys) == len(sys_end)
    assert sys.composition == sys_end.composition
    # The geometric center of each molecule should be more or less equal
    for mol1, mol2 in zip(sys, sys_end):
        geom1 = mol1.geometric_center
        geom2 = mol2.geometric_center
        assert np.allclose(geom1, geom2, rtol=tol, atol=tol)
Esempio n. 2
0
    def test_initialization(self):
        """
        Test System initialization with a system with molecules with multiple
        residues.
        """
        fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
        fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
        fitpSDS = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/SDS_AA.itp')
        fitpADN = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_CG.itp')

        with pytest.raises(IOError):
            _ = System(fgro, fitpSDS)

        empty = System(fgro)
        assert not empty.different_molecules
        with pytest.raises(IOError, match=r'The molecule.*'):
            empty.add_molecule_top(MoleculeTop(fitpSDS))

        bad_dna_top = MoleculeTop(fitpADN)

        for atom in bad_dna_top[98:105]:
            atom.resname = 'DA'
        for atom in bad_dna_top[105:112]:
            atom.resname = 'DG'

        with pytest.raises(IOError, match=r'The sequence.*'):
            empty.add_molecule_top(bad_dna_top)

        empty.add_molecule_top(MoleculeTop(fitpADN))
Esempio n. 3
0
def molecule_DNA_map() -> Molecule:
    """
    Molecule instance of DNA in coarse-grained resolution after being mapped.
    """
    fitpDNA = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_CG.itp')
    fgroDNA = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_map.gro')
    return System(fgroDNA, fitpDNA)[0]
Esempio n. 4
0
def molecule_DNA_AA() -> Molecule:
    """
    Molecule instance of DNA in all-atom resolution.
    """
    fitpDNA = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_AA.itp')
    fgroDNA = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_AA.gro')
    return System(fgroDNA, fitpDNA)[0]
Esempio n. 5
0
def protein_cg() -> Molecule:
    """
    Molecule instance of a protein coarse-grained.
    """
    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_CG.gro')
    fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_CG.itp')
    return System(fgro, fitp)[0]
Esempio n. 6
0
def protein_aa() -> Molecule:
    """
    Molecule instance of a protein all-atom.
    """
    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_AA.gro')
    fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_AA.itp')
    return System(fgro, fitp)[0]
Esempio n. 7
0
def bf4_cg() -> Molecule:
    """
    Molecule instance of BF4 in coarse-grained resolution.
    """
    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BF4_CG.gro')
    fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BF4_CG.itp')
    return System(fgro, fitp)[0]
Esempio n. 8
0
def bf4_aa() -> Molecule:
    """
    Molecule instance of BF4 in all-atom resolution.
    """
    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BF4_AA.gro')
    fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BF4_AA.itp')
    return System(fgro, fitp)[0]
Esempio n. 9
0
def system() -> System:
    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
    fitpDNA = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_CG.itp')
    fitpDPSM = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DPSM_CG.itp')
    fitpVTE = os.path.join(ACTUAL_PATH,
                           '../../gaddlemaps/data/vitamin_E_CG.itp')
    return System(fgro, fitpDNA, fitpDPSM, fitpVTE)
Esempio n. 10
0
def vte_cg() -> Molecule:
    """
    Molecule instance of vitamin E coarse-grained.
    """
    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
    fitp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/vitamin_E_CG.itp')
    return System(fgro, fitp)[0]
Esempio n. 11
0
def system() -> System:
    """
    System instance with DNA and E vitamin E molecules.
    """

    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
    fgro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
    fitpDNA = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_CG.itp')
    fitpVTE = os.path.join(ACTUAL_PATH,
                           '../../gaddlemaps/data/vitamin_E_CG.itp')
    return System(fgro, fitpDNA, fitpVTE)
Esempio n. 12
0
    def test_extrapolate(self, manager: Manager, molecule_DNA_map: Molecule,
                         molecule_VTE_map: Molecule, system: System,
                         molecule_VTE_AA: Molecule, molecule_DNA_AA: Molecule,
                         tmp_path: Path):
        """
        Tests the extrapolation functionality.
        """
        subdir = tmp_path / "manager_test"
        subdir.mkdir()
        fname = str(subdir / "system_CG_mapped_test.gro")

        with pytest.raises(SystemError):
            _ = manager.extrapolate_system(fname)

        manager.molecule_correspondence['VTE'].start = molecule_VTE_map
        manager.molecule_correspondence['DNA'].start = molecule_DNA_map

        manager.add_end_molecules(molecule_DNA_AA, molecule_VTE_AA)

        tot = manager.complete_correspondence
        assert 'DNA' in tot
        assert 'VTE' in tot

        manager.calculate_exchange_maps()

        manager.extrapolate_system(fname)

        fgro = fname
        fitpDNA = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_AA.itp')
        fitpVTE = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/VTE_AA.itp')
        sys_end = System(fgro, fitpDNA, fitpVTE)

        poss = system[0].atoms_positions
        tol = 0.1 * np.linalg.norm(np.max(poss, 0) + np.min(poss, 0))

        assert len(system) == len(sys_end)
        assert system.composition == sys_end.composition
        # The geometric center of each molecule should be more or less equal
        for mol1, mol2 in zip(system, sys_end):
            assert np.allclose(mol1.geometric_center,
                               mol2.geometric_center,
                               rtol=tol,
                               atol=tol)
Esempio n. 13
0
def test_map_system(tmp_path: Path):
    """
    Tests the whole mapping process.
    """
    sys = System(SYS_CG_GRO, VTE_CG_ITP, DNA_CG_ITP)

    man = Manager(sys)

    svte = System(VTE_AA_GRO, VTE_AA_ITP)[0]
    sdna = System(DNA_AA_GRO, DNA_AA_ITP)[0]

    man.add_end_molecules(svte, sdna)

    start_dna = System(DNA_CG_MAP_GRO, DNA_CG_ITP)[0]
    start_vte = System(VTE_CG_MAP_GRO, VTE_CG_ITP)[0]

    # Tolerance in comparison
    poss = sys[0].atoms_positions
    tol = 0.1 * np.linalg.norm(np.max(poss, 0) + np.min(poss, 0))

    subdir = tmp_path / "complete_alg_test"
    subdir.mkdir()
    fname = str(subdir / "system_CG_mapped_test.gro")

    # Test aligning and not
    for i in range(2):
        if i:
            man.align_molecules()
        else:
            man.molecule_correspondence['VTE'].start = start_vte
            man.molecule_correspondence['DNA'].start = start_dna

        man.calculate_exchange_maps()

        man.extrapolate_system(fname)

        sys_end = System(fname, VTE_AA_ITP, DNA_AA_ITP)

        assert len(sys) == len(sys_end)
        assert sys.composition == sys_end.composition
        # The geometric center of each molecule should be more or less equal
        for mol1, mol2 in zip(sys, sys_end):
            assert np.allclose(mol1.geometric_center, mol2.geometric_center,
                               rtol=tol)
Esempio n. 14
0
from gaddlemaps.components import System


ACTUAL_PATH = os.path.split(os.path.join(os.path.abspath(__file__)))[0]

Protein_cg_gro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_CG.gro')
Protein_cg_itp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_CG.itp')

Protein_aa_gro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_AA.gro')
Protein_aa_itp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/Protein_AA.itp')

n_test = 1
times = np.empty(n_test)

for i in range(n_test):
    Protein_cg = System(Protein_cg_gro, Protein_cg_itp)[0]
    Protein_aa = System(Protein_aa_gro, Protein_aa_itp)[0]

    ali = Alignment(Protein_cg, Protein_aa)
    start = time.time()
    ali.align_molecules()
    end = time.time()
    time_i = end - start
    times[i] = time_i
    print(f'Guessed restrains: {time_i}')

avg = np.mean(times)
std = np.std(times)
print(f'Average time {avg} +- {std}')

Esempio n. 15
0
# the IL mapping example, in other words, we are not going to use the `Manager`
# class. Doing the mapping in this way will allow you for example to force the
# molecule corresponding even when molecules in the initial and final
# resolution do not match.
#
# ## Initializing the system and the components
#
# The first thing that we need to do is to load the objects with the
# information of the system that we want to map. So firstly, we are going to
# initialize a `System` object with no information about the molecular
# connections. This will create an empty system (no molecules are recognized):

from gaddlemaps import DATA_FILES_PATH
from gaddlemaps.components import System

system = System(DATA_FILES_PATH['system_CG.gro'])
print(system)

# Now we are going to load the molecules that we want to map. The solvent
# molecules as well as the ions are not recommended to be mapped to gain
# performance. Moreover, the system can be resolvated again once it is in the
# final resolution. That said, we load only the DNA fragment, the DPSM and VTE:

system.add_ftop(DATA_FILES_PATH['DNA_CG.itp'])
system.add_ftop(DATA_FILES_PATH['vitamin_E_CG.itp'])
system.add_ftop(DATA_FILES_PATH['DPSM_CG.itp'])
print(system)

# Now we need to create the exchange maps for each type of molecules to finally
# extrapolate the found mapping to the whole system. For these exchange maps we
# need a representation for each type of molecules in both initial and final
Esempio n. 16
0
# resolvate the system once you have mapped the rest of the molecules. In that
# case, you should not pass the topology file of the water to the Manager
# initialization.

manager = Manager.from_files('../../gaddlemaps/data/system_bmimbf4_cg.gro',
                             '../../gaddlemaps/data/BMIM_CG.itp',
                             '../../gaddlemaps/data/BF4_CG.itp')

# Now, we need to specify the molecules in the final resolution (AA). In this
# example, we initialize two instances of Molecule, one for the BMIM molecule
# and other for the BF4 one. For this task, we create a System object with the
# gro and the corresponding topology files. Then, we take the first element of
# these systems which are the desired molecules (as the input gro files only
# contain one molecule).

bmim_aa = System('../../gaddlemaps/data/BMIM_AA.gro',
                 '../../gaddlemaps/data/BMIM_AA.itp')[0]
bf4_aa = System('../../gaddlemaps/data/BF4_AA.gro',
                '../../gaddlemaps/data/BF4_AA.itp')[0]

# We could also have created these molecules with the Molecule.from_file method

bmim_aa = Molecule.from_files('../../gaddlemaps/data/BMIM_AA.gro',
                              '../../gaddlemaps/data/BMIM_AA.itp')
bf4_aa = Molecule.from_files('../../gaddlemaps/data/BF4_AA.gro',
                             '../../gaddlemaps/data/BF4_AA.itp')

# Once the molecules are created, we need to specify which one correspond with
# the molecules in the initial resolution. For that, we have 2 options. First,
# we can use the add_end_molecules method of Manager, which will automatically
# detect the corresponding molecules based on their names attribute.
Esempio n. 17
0
from gaddlemaps import Alignment
from gaddlemaps.components import System


ACTUAL_PATH = os.path.split(os.path.join(os.path.abspath(__file__)))[0]


dna_aa_itp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_AA.itp')
dna_aa_gro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_AA.gro')


sys_cg_gro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
sys_cg_gro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/system_CG.gro')
dna_cg_itp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/DNA_CG.itp')
sys = System(sys_cg_gro, dna_cg_itp)

Protein_cg = sys[0]
Protein_aa = System(dna_aa_gro, dna_aa_itp)[0]

ali = Alignment(Protein_cg, Protein_aa)

start = time.time()
ali.align_molecules()
end = time.time()

time_i = end - start
print(f'Guessed restrains: {time_i}')

ali.write_comparative_gro('check_dna.gro')
Esempio n. 18
0
ACTUAL_PATH = os.path.split(os.path.join(os.path.abspath(__file__)))[0]

bmim_aa_itp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BMIM_AA.itp')
bmim_aa_gro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BMIM_AA.gro')

bf4_aa_itp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BF4_AA.itp')
bf4_aa_gro = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BF4_AA.gro')

bmim_cg_itp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BMIM_CG.itp')
bf4_cg_itp = os.path.join(ACTUAL_PATH, '../../gaddlemaps/data/BF4_CG.itp')

bmimbf4_sys = os.path.join(ACTUAL_PATH,
                           '../../gaddlemaps/data/system_bmimbf4_cg.gro')

system = System(bmimbf4_sys, bmim_cg_itp, bf4_cg_itp)
bmim = System(bmim_aa_gro, bmim_aa_itp)[0]
bf4 = System(bf4_aa_gro, bf4_aa_itp)[0]
man = Manager(system)
man.add_end_molecule(bmim)
man.add_end_molecule(bf4)
man.align_molecules()
man.calculate_exchange_maps()

fname = os.path.join(ACTUAL_PATH,
                     '../../gaddlemaps/data/system_CG_mapeado_test.gro')
fname = os.path.join(ACTUAL_PATH,
                     '../../gaddlemaps/data/system_CG_mapeado_test.gro')
try:
    man.extrapolate_system(fname)
except: