コード例 #1
0
    def test_solvation_packmol_tip3p(self):
        # Complex file name
        fcomplex = "tests/data/Bace_protein.pdb"

        # Read OEMol molecule
        mol = oechem.OEMol()

        with oechem.oemolistream(fcomplex) as ifs:
            oechem.OEReadMolecule(ifs, mol)

        # Solvate the system
        solv_complex = packmol.oesolvate(mol,
                                         density=1.0,
                                         padding_distance=10.0,
                                         distance_between_atoms=2.0,
                                         solvents='tip3p',
                                         molar_fractions='1.0',
                                         geometry='box',
                                         close_solvent=True,
                                         salt='[Na+], [Cl-]',
                                         salt_concentration=100.0,
                                         neutralize_solute=True)

        prot, lig, wat, other = utils.split(solv_complex)

        npa = prot.GetMaxAtomIdx()
        nla = lig.GetMaxAtomIdx()
        noa = other.GetMaxAtomIdx()
        nwa = wat.GetMaxAtomIdx()

        self.assertEqual(npa, 6044)
        self.assertEqual(nla, 0)
        # Ions added to excipients
        self.assertEqual(noa, 94)
        # Water molecules added
        self.assertEqual(nwa, 48279)

        box_vectors = solv_complex.GetData('box_vectors')
        box_vectors = data_utils.decodePyObj(box_vectors)
        box_vectors = box_vectors.in_units_of(unit.nanometers)

        self.assertAlmostEqual(box_vectors[0][0] / unit.nanometers,
                               8.23,
                               delta=0.01)
        self.assertEqual(box_vectors[0][1] / unit.nanometers, 0.0)
        self.assertEqual(box_vectors[0][2] / unit.nanometers, 0.0)

        self.assertAlmostEqual(box_vectors[1][1] / unit.nanometers,
                               8.23,
                               delta=0.01)
        self.assertEqual(box_vectors[1][0] / unit.nanometers, 0.0)
        self.assertEqual(box_vectors[1][2] / unit.nanometers, 0.0)

        self.assertAlmostEqual(box_vectors[2][2] / unit.nanometers,
                               8.23,
                               delta=0.01)
        self.assertEqual(box_vectors[2][0] / unit.nanometers, 0.0)
        self.assertEqual(box_vectors[2][1] / unit.nanometers, 0.0)
コード例 #2
0
ファイル: test_funcs.py プロジェクト: oess/oeommtools
    def test_solvation_packmol_components(self):
        # Complex file name
        fcomplex = "tests/data/Bace_protein.pdb"

        # Read OEMol molecule
        mol = oechem.OEMol()

        with oechem.oemolistream(fcomplex) as ifs:
            oechem.OEReadMolecule(ifs, mol)

        # Solvate the system
        solv_complex, solvent, salt, counter_ions = packmol.oesolvate(
            mol,
            density=1.0,
            padding_distance=10.0,
            distance_between_atoms=2.0,
            solvents='tip3p',
            molar_fractions='1.0',
            geometry='box',
            close_solvent=True,
            salt='[Na+], [Cl-]',
            salt_concentration=100.0,
            neutralize_solute=True,
            return_components=True)

        prot, lig, wat, cofactors, lipids, metals, excipients = utils.split(
            solv_complex)

        npa = prot.GetMaxAtomIdx()
        nla = lig.GetMaxAtomIdx()
        noa = excipients.GetMaxAtomIdx()
        nwa = wat.GetMaxAtomIdx()
        nlpa = lipids.GetMaxAtomIdx()
        nma = metals.GetMaxAtomIdx()
        nca = cofactors.GetMaxAtomIdx()

        self.assertEqual(npa, 6044)
        self.assertEqual(nla, 0)
        self.assertEqual(nlpa, 0)
        self.assertEqual(nca, 0)
        self.assertEqual(nma, 0)

        # The Bace system has 19 water molecules
        self.assertEqual(nwa, solvent.NumAtoms() + 19 * 3)

        # The Bace system has the TLA excipient with 14 atoms
        self.assertEqual(noa, salt.NumAtoms() + counter_ions.NumAtoms() + 14)
コード例 #3
0
ファイル: cubes.py プロジェクト: zeromtmu/openmm_orion
    def process(self, solute, port):

        try:
            opt = dict(self.opt)
            # Update cube simulation parameters with the eventually molecule SD tags
            new_args = {
                dp.GetTag(): dp.GetValue()
                for dp in oechem.OEGetSDDataPairs(solute)
                if dp.GetTag() in ["solvents", "molar_fractions", "density"]
            }
            if new_args:
                for k in new_args:
                    if k == 'molar_fractions':
                        continue
                    try:
                        new_args[k] = float(new_args[k])
                    except:
                        pass
                self.log.info(
                    "Updating parameters for molecule: {}\n{}".format(
                        solute.GetTitle(), new_args))
                opt.update(new_args)

            # Solvate the system
            sol_system = oesolvate(solute, **opt)
            self.log.info("Solvated System atom number {}".format(
                sol_system.NumAtoms()))
            sol_system.SetTitle(solute.GetTitle())
            self.success.emit(sol_system)
        except Exception as e:
            # Attach error message to the molecule that failed
            self.log.error(traceback.format_exc())
            solute.SetData('error', str(e))
            # Return failed mol
            self.failure.emit(solute)

        return
コード例 #4
0
ファイル: test_funcs.py プロジェクト: oess/oeommtools
    def test_solvation_packmol_components_None(self):
        # Complex file name
        fcomplex = "tests/data/Bace_protein.pdb"

        # Read OEMol molecule
        mol = oechem.OEMol()

        with oechem.oemolistream(fcomplex) as ifs:
            oechem.OEReadMolecule(ifs, mol)

        # Solvate the system
        solv_complex, solvent, salt, counter_ions = packmol.oesolvate(
            mol,
            density=1.0,
            padding_distance=10.0,
            distance_between_atoms=2.0,
            solvents='tip3p',
            molar_fractions='1.0',
            geometry='box',
            close_solvent=True,
            salt='[Na+], [Cl-]',
            salt_concentration=0.0,
            neutralize_solute=False,
            return_components=True)

        prot, lig, wat, cofactors, lipids, metals, excipients = utils.split(
            solv_complex)

        npa = prot.GetMaxAtomIdx()
        nla = lig.GetMaxAtomIdx()

        self.assertEqual(npa, 6044)
        self.assertEqual(nla, 0)

        assert salt is None
        assert counter_ions is None
コード例 #5
0
ファイル: cubes.py プロジェクト: oess/openmm_orion
    def process(self, record, port):

        try:
            opt = dict(self.opt)

            if not record.has_value(Fields.md_components):
                raise ValueError("Missing the MD Components Field")

            md_components = record.get_value(Fields.md_components)

            solute, map_comp = md_components.create_flask

            if not record.has_value(Fields.title):
                self.log.warn("Missing Title field")
                solute_title = solute.GetTitle()[0:12]
            else:
                solute_title = record.get_value(Fields.title)

            self.log.info("[{}] solvating flask {}".format(
                self.title, solute_title))

            # Update cube simulation parameters
            for field in record.get_fields(include_meta=True):
                field_name = field.get_name()
                if field_name in ['molar_fractions', 'density', 'solvents']:
                    rec_value = record.get_value(field)
                    if field_name == 'molar_fractions':
                        opt[field_name] = str(rec_value)
                    else:
                        opt[field_name] = rec_value
                    opt['Logger'].info(
                        "{} Updating parameters for molecule: {} {} = {}".
                        format(self.title, solute.GetTitle(), field_name,
                               rec_value))
            # Set the flag to return the solvent molecule components
            opt['return_components'] = True

            # Solvate the system
            sol_system, solvent, salt, counter_ions = packmol.oesolvate(
                solute, **opt)

            # Separate the Water from the solvent
            pred_water = oechem.OEIsWater(checkHydrogens=True)
            water = oechem.OEMol()
            oechem.OESubsetMol(water, solvent, pred_water)

            if water.NumAtoms():
                if md_components.has_water:

                    water_comp = md_components.get_water

                    if not oechem.OEAddMols(water_comp, water):
                        raise ValueError(
                            "Cannot add the MD Component Water and the Packmol Water"
                        )

                    md_components.set_water(water_comp)

                else:
                    md_components.set_water(water)

                pred_not_water = oechem.OENotAtom(
                    oechem.OEIsWater(checkHydrogens=True))
                solvent_not_water = oechem.OEMol()
                oechem.OESubsetMol(solvent_not_water, solvent, pred_not_water)

                if solvent_not_water.NumAtoms():
                    solvent = solvent_not_water
                else:
                    solvent = oechem.OEMol()

            self.log.info(
                "[{}] Solvated simulation flask {} yielding {} atoms overall".
                format(self.title, solute_title, sol_system.NumAtoms()))
            sol_system.SetTitle(solute.GetTitle())

            if salt is not None and counter_ions is not None:
                if not oechem.OEAddMols(counter_ions, salt):
                    raise ValueError(
                        "Cannot add the salt component and the counter ion component"
                    )
            elif salt is not None:
                counter_ions = salt
            else:
                pass

            if md_components.has_solvent:
                solvent_comp = md_components.get_solvent
                if not oechem.OEAddMols(solvent_comp, solvent):
                    raise ValueError(
                        "Cannot add the MD Component solvent and the Packmol Solvent"
                    )
            else:
                solvent_comp = solvent

            if solvent_comp.NumAtoms():
                md_components.set_solvent(solvent_comp)

            if counter_ions is not None:
                if md_components.has_counter_ions:
                    counter_ions_comp = md_components.get_counter_ions
                    if not oechem.OEAddMols(counter_ions_comp, counter_ions):
                        raise ValueError(
                            "Cannot add the MD Component counter ions and the Packmol counter ions"
                        )
                else:
                    counter_ions_comp = counter_ions

                md_components.set_counter_ions(counter_ions_comp)

            # Set Box Vectors
            vec_data = pack_utils.getData(sol_system, tag='box_vectors')
            box_vec = pack_utils.decodePyObj(vec_data)
            md_components.set_box_vectors(box_vec)

            flask, map_comp = md_components.create_flask
            record.set_value(Fields.md_components, md_components)
            record.set_value(Fields.flask, flask)
            record.set_value(Fields.title, solute_title)

            self.success.emit(record)

        except Exception as e:

            print("Failed to complete", str(e), flush=True)
            self.opt['Logger'].info('Exception {} {}'.format(
                str(e), self.title))
            self.log.error(traceback.format_exc())
            self.failure.emit(record)

        return