Пример #1
0
    def __init__(self, dihedral, molecule=None, top_indexes=None, potential=None):
        """
           Arguments
            | ``dihedral`` -- the index of the atoms that define the dihedral
                              angle

           Optional arguments
            | ``molecule`` -- a molecule object. required when top_indexes is not
                              given
            | ``top_indexes`` -- a list of atom indexes involved in the rotor.
                                 required when molecule is not given
            | ``potential`` -- rotational potential info (if this is a hindered
                               rotor). must be a two-tuple containing the angles
                               and the corresponding energies.

        """
        self.dihedral = dihedral
        if top_indexes is None:
            # try to deduce the top indexes
            if molecule is None:
                raise ValueError("missing arguemt: top_indexes or molecule from which top_indexes can be derived")
            atom0, atom1 = dihedral[1:3]
            graph = MolecularGraph.from_geometry(molecule)
            half0, half1 = graph.get_halfs(atom0, atom1)
            if len(half1) > len(half0):
                top_indexes = half0
                top_indexes.discard(atom0)
            else:
                top_indexes = half1
                top_indexes.discard(atom1)
            top_indexes = tuple(top_indexes)
        self.top_indexes = top_indexes
        self.potential = potential
Пример #2
0
    def __init__(self,
                 dihedral,
                 molecule=None,
                 top_indexes=None,
                 potential=None):
        """
           Arguments
            | ``dihedral`` -- the index of the atoms that define the dihedral
                              angle

           Optional arguments
            | ``molecule`` -- a molecule object. required when top_indexes is not
                              given
            | ``top_indexes`` -- a list of atom indexes involved in the rotor.
                                 required when molecule is not given or when the
                                 top_indexes can not be derived automatically.
            | ``potential`` -- rotational potential info (if this is a hindered
                               rotor). must be a two-tuple containing the angles
                               and the corresponding energies.

        """
        self.dihedral = dihedral
        if top_indexes is None:
            # try to deduce the top indexes
            if molecule is None:
                raise ValueError(
                    "missing arguemt: top_indexes or molecule from which top_indexes can be derived"
                )
            atom0, atom1 = dihedral[1:3]
            graph = MolecularGraph.from_geometry(molecule)
            half0, half1 = graph.get_halfs(atom0, atom1)
            if (len(half0) + len(half1) !=
                    molecule.size) or len(half0) == 1 or len(half1) == 1:
                raise ValueError(
                    "The rotating top could not be assigned properly. Specify the top_indexes manually."
                )
            if len(half1) > len(half0):
                top_indexes = half0
                top_indexes.discard(atom0)
            else:
                top_indexes = half1
                top_indexes.discard(atom1)
            top_indexes = tuple(top_indexes)
        else:
            # check the sanity of the top indexes
            if not ((self.dihedral[0] in top_indexes) ^
                    (self.dihedral[3] in top_indexes)):
                raise ValueError(
                    'The top must contain either first or the last atom of the dihedral angle.'
                )
            if ((self.dihedral[1] in top_indexes) |
                (self.dihedral[2] in top_indexes)):
                raise ValueError(
                    'The top may not contain atoms from the central bond of the dihedral angle.'
                )
        self.top_indexes = top_indexes
        self.potential = potential
Пример #3
0
def get_precursor_model():
    m = XYZFile("test/input/mfi_precursor.xyz").get_molecule()
    mgraph = MolecularGraph.from_geometry(m)
    connect_masks = np.array([
        number == 8 and len(mgraph.neighbors[index]) == 1
        for index, number in enumerate(m.numbers)
    ], bool)
    radii = np.array([
        periodic[number].vdw_radius * {True: 0.3, False: 1.0}[connect_mask]
        for number, connect_mask in zip(m.numbers, connect_masks)
    ], float)
    radii += np.random.uniform(0, 0.1, radii.shape)
    return m.coordinates, connect_masks, radii
Пример #4
0
    def __init__(self, dihedral, molecule=None, top_indexes=None, potential=None):
        """
           Arguments
            | ``dihedral`` -- the index of the atoms that define the dihedral
                              angle

           Optional arguments
            | ``molecule`` -- a molecule object. required when top_indexes is not
                              given
            | ``top_indexes`` -- a list of atom indexes involved in the rotor.
                                 required when molecule is not given or when the
                                 top_indexes can not be derived automatically.
            | ``potential`` -- rotational potential info (if this is a hindered
                               rotor). must be a two-tuple containing the angles
                               and the corresponding energies.

        """
        self.dihedral = dihedral
        if top_indexes is None:
            # try to deduce the top indexes
            if molecule is None:
                raise ValueError("missing arguemt: top_indexes or molecule from which top_indexes can be derived")
            atom0, atom1 = dihedral[1:3]
            graph = MolecularGraph.from_geometry(molecule)
            half0, half1 = graph.get_halfs(atom0, atom1)
            if (len(half0) + len(half1) != molecule.size) or len(half0) == 1 or len(half1) == 1:
                raise ValueError("The rotating top could not be assigned properly. Specify the top_indexes manually.")
            if len(half1) > len(half0):
                top_indexes = half0
                top_indexes.discard(atom0)
            else:
                top_indexes = half1
                top_indexes.discard(atom1)
            top_indexes = tuple(top_indexes)
        else:
            # check the sanity of the top indexes
            if not ((self.dihedral[0] in top_indexes) ^ (self.dihedral[3] in top_indexes)):
                raise ValueError('The top must contain either first or the last atom of the dihedral angle.')
            if ((self.dihedral[1] in top_indexes) | (self.dihedral[2] in top_indexes)):
                raise ValueError('The top may not contain atoms from the central bond of the dihedral angle.')
        self.top_indexes = top_indexes
        self.potential = potential