def setUp(self):
        """
        Set up tests.
        """
        super(TestPBSA, self).setUp()

        # get charges and radii
        antechamber = amber_utils.Antechamber()
        self.charges, self.radii = antechamber.get_charges_and_radii(self.mol)
Exemple #2
0
    def calculate_esp(self, mol):
        """
        Calculate electrostatic potential grid.

        Procedure
        ---------
        1. Prepare molecule by adding hydrogens and canonicalizing the
            orientation and alignment.
        2. Calculate charges and radii with Antechamber.
        3. Calculate electrostatic potential grids with PBSA.

        PBSA requires PQR input, which is similar to PDB with charge and
        radius information added. Neither Antechamber nor PBSA take piped
        input, so we have to use a lot of temporary files and directories.

        Parameters
        ----------
        mol : RDMol
            Molecule.
        """

        # the molecule must have at least one conformer
        if mol.GetNumConformers() < 1:
            name = ''
            if mol.HasProp('_Name'):
                name = mol.GetProp('_Name')
            raise AssertionError(
                "Molecule '{}' has zero conformers.".format(name))

        # calculate charges and radii
        antechamber = amber_utils.Antechamber()
        charges, radii = antechamber.get_charges_and_radii(mol)

        # get ESP grid for each conformer
        grids = []
        pbsa = amber_utils.PBSA(self.size, self.resolution, self.nb_cutoff,
                                self.ionic_strength)
        for i, conf in enumerate(mol.GetConformers()):
            try:
                grid, center = pbsa.get_esp_grid(mol, charges, radii,
                                                 conf_id=conf.GetId())
                assert center == (0, 0, 0)  # should be centered on the origin
                grids.append(grid)
            except subprocess.CalledProcessError as e:
                print e
                if mol.HasProp('_Name'):
                    name = mol.GetProp('_Name')
                else:
                    name = Chem.MolToSmiles(mol, isomericSmiles=True)
                warnings.warn(
                    "Conformer {} of molecule '{}' failed ".format(i, name) +
                    "ESP calculation.".format(name))
                grids.append(None)

        grids = np.asarray(grids)
        return grids
 def test_antechamber_charges_and_radii(self):
     """
     Test Antechamber charges and radii.
     """
     antechamber = amber_utils.Antechamber()
     charges, radii = antechamber.get_charges_and_radii(self.mol)
     assert charges.size == 21  # 21 atoms: C_9H_8O_4
     assert np.allclose(charges.sum(), 0)  # neutral molecule
     assert radii.size == 21  # 12 atoms
     assert np.count_nonzero(radii > 0)  # no zero radii