示例#1
0
 def evaluatorParameters(self, universe, subset1, subset2, global_data):
     if universe.is_periodic and \
             (len(self.atom_indices_1) > 1 or len(self.atom_indices_1) > 1):
         raise ValueError("Center-of-mass restraints not implemented"
                          " for periodic universes")
     ok = False
     for s1, s2 in [(subset1, subset2), (subset2, subset1)]:
         if s1 is None and s1 is None:
             ok = True
             break
         s1 = set(a.index for a in s1.atomIterator())
         diff1 = set(self.atom_indices_1).difference(s1)
         s2 = set(a.index for a in s2.atomIterator())
         diff2 = set(self.atom_indices_2).difference(s2)
         if not diff1 and not diff2:
             # Each object is in one of the subsets
             ok = True
             break
         if (diff1 and len(diff1) != len(self.atom_indices_1)) \
                 or (diff2 and len(diff2) != len(self.atom_indices_2)):
             # The subset contains some but not all of the
             # restrained atoms.
             raise ValueError("Restrained atoms partially " "in a subset")
     global_data.add('initialized', self.__class__)
     if not ok:
         # The objects are not in the subsets, so there is no
         # contribution to the total energy.
         return {'harmonic_distance_cm': []}
     if self.nb_exclusion:
         assert len(self.atom_indices_1) == 1
         assert len(self.atom_indices_2) == 1
         i1 = self.atom_indices_1[0]
         i2 = self.atom_indices_2[0]
         global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     if len(self.atom_indices_1) == 1 and len(self.atom_indices_2) == 1:
         # Keep the old format for the single-atom case for best
         # compatibility with older MMTK versions.
         return {
             'harmonic_distance_term':
             [(self.atom_indices_1[0], self.atom_indices_2[0],
               self.distance, self.force_constant)]
         }
     else:
         return {
             'harmonic_distance_cm':
             [(self.atom_indices_1, self.atom_indices_2, self.distance,
               self.force_constant)]
         }
示例#2
0
 def addBondTerm(self, data, bond, object, global_data):
     a1 = bond.a1
     a2 = bond.a2
     i1 = a1.index
     i2 = a2.index
     global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     try:
         p = self.dataset.bondParameters(t1, t2)
     except KeyError:
         raise KeyError(
             ('No parameters for bond %s (atom type %s)' +
              ' - %s (atom type %s)') % (str(a1), t1, str(a2), t2))
     if p is not None and p[1] != 0.:
         data.add('bonds', (i1, i2, p[0], p[1] * self.scale_factor))
示例#3
0
 def addBondTerm(self, data, bond, object, global_data):
     a1 = bond.a1
     a2 = bond.a2
     i1 = a1.index
     i2 = a2.index
     global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     try:
         p = self.dataset.bondParameters(t1, t2)
     except KeyError:
         raise KeyError(('No parameters for bond %s (atom type %s)' +
                         ' - %s (atom type %s)') % (str(a1), t1,
                                                    str(a2), t2))
     if p is not None and p[1] != 0.:
         data.add('bonds', (i1, i2, p[0], p[1]*self.scale_factor))
示例#4
0
 def addBondTerm(self, data, bond, object, global_data):
     if not self.arguments[0]:
         return
     a1 = bond.a1
     a2 = bond.a2
     i1 = a1.index
     i2 = a2.index
     global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     try:
         p = self.dataset.bondParameters(t1, t2)
     except KeyError:
         raise KeyError('No parameters for bond ' + `a1` +  '--' + `a2`)
     if p is not None:
         d = data.get('universe').distance(a1, a2)
         data.add('bonds', (i1, i2, d, p[1]))
示例#5
0
 def addBondTerm(self, data, bond, object, global_data):
     if not self.arguments[0]:
         return
     a1 = bond.a1
     a2 = bond.a2
     i1 = a1.index
     i2 = a2.index
     global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     try:
         p = self.dataset.bondParameters(t1, t2)
     except KeyError:
         raise KeyError('No parameters for bond ' + a1 +  '--' + a2)
     if p is not None:
         d = data.get('universe').distance(a1, a2)
         data.add('bonds', (i1, i2, d, p[1]))
示例#6
0
 def evaluatorParameters(self, universe, subset1, subset2, global_data):
     if universe.is_periodic and \
             (len(self.atom_indices_1) > 1 or len(self.atom_indices_1) > 1):
         raise ValueError("Center-of-mass restraints not implemented"
                          " for periodic universes")
     ok = False
     for s1, s2 in [(subset1, subset2), (subset2, subset1)]:
         if s1 is None and s1 is None:
             ok = True
             break
         s1 = set(a.index for a in s1.atomIterator())
         diff1 = set(self.atom_indices_1).difference(s1)
         s2 = set(a.index for a in s2.atomIterator())
         diff2 = set(self.atom_indices_2).difference(s2)
         if not diff1 and not diff2:
             # Each object is in one of the subsets
             ok = True
             break
         if (diff1 and len(diff1) != len(self.atom_indices_1)) \
                 or (diff2 and len(diff2) != len(self.atom_indices_2)):
             # The subset contains some but not all of the
             # restrained atoms.
             raise ValueError("Restrained atoms partially "
                              "in a subset")
     global_data.add('initialized', self.__class__)
     if not ok:
         # The objects are not in the subsets, so there is no
         # contribution to the total energy.
         return {'harmonic_distance_cm': []}
     if self.nb_exclusion:
         assert len(self.atom_indices_1) == 1 
         assert len(self.atom_indices_2) == 1
         i1 = self.atom_indices_1[0]
         i2 = self.atom_indices_2[0]
         global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     if len(self.atom_indices_1) == 1 and len(self.atom_indices_2) == 1:
         # Keep the old format for the single-atom case for best
         # compatibility with older MMTK versions.
         return {'harmonic_distance_term':
                 [(self.atom_indices_1[0], self.atom_indices_2[0],
                   self.distance, self.force_constant)]}
     else:
         return {'harmonic_distance_cm':
                 [(self.atom_indices_1, self.atom_indices_2,
                   self.distance, self.force_constant)]}
示例#7
0
 def addBondAngleTerm(self, data, angle, object, global_data):
     a1 = angle.a1
     a2 = angle.a2
     ca = angle.ca
     i1 = a1.index
     i2 = a2.index
     ic = ca.index
     global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     tc = global_data.atom_type[ca]
     try:
         p = self.dataset.bondAngleParameters(t1, tc, t2)
     except KeyError:
         raise KeyError(('No parameters for angle %s (atom type %s)' +
                         ' - %s (atom type %s) - %s (atom type %s)') %
                        (str(a1), t1, str(ca), tc, str(a2), t2))
     if p is not None and p[1] != 0.:
         data.add('angles', (i1, ic, i2, p[0], p[1] * self.scale_factor))
示例#8
0
 def addBondAngleTerm(self, data, angle, object, global_data):
     a1 = angle.a1
     a2 = angle.a2
     ca = angle.ca
     i1 = a1.index
     i2 = a2.index
     ic = ca.index
     global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     tc = global_data.atom_type[ca]
     try:
         p = self.dataset.bondAngleParameters(t1, tc, t2)
     except KeyError:
         raise KeyError(('No parameters for angle %s (atom type %s)' +
                         ' - %s (atom type %s) - %s (atom type %s)')
                        % (str(a1), t1, str(ca), tc, str(a2), t2))
     if p is not None and p[1] != 0.:
         data.add('angles', (i1, ic, i2, p[0], p[1]*self.scale_factor))
示例#9
0
 def addDihedralTerm(self, data, dihedral, object, global_data):
     a1 = dihedral.a1
     a2 = dihedral.a2
     a3 = dihedral.a3
     a4 = dihedral.a4
     i1 = a1.index
     i2 = a2.index
     i3 = a3.index
     i4 = a4.index
     global_data.add('1_4_pairs', Utility.normalizePair((i1, i4)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     t3 = global_data.atom_type[a3]
     t4 = global_data.atom_type[a4]
     terms = self.dataset.dihedralParameters(t1, t2, t3, t4)
     if terms is not None:
         for p in terms:
             if p[2] != 0.:
                 data.add('dihedrals', (i1, i2, i3, i4,
                                        p[0], p[1], p[2]*self.scale_factor))
示例#10
0
 def addDihedralTerm(self, data, dihedral, object, global_data):
     a1 = dihedral.a1
     a2 = dihedral.a2
     a3 = dihedral.a3
     a4 = dihedral.a4
     i1 = a1.index
     i2 = a2.index
     i3 = a3.index
     i4 = a4.index
     global_data.add('1_4_pairs', Utility.normalizePair((i1, i4)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     t3 = global_data.atom_type[a3]
     t4 = global_data.atom_type[a4]
     terms = self.dataset.dihedralParameters(t1, t2, t3, t4)
     if terms is not None:
         for p in terms:
             if p[2] != 0.:
                 data.add(
                     'dihedrals',
                     (i1, i2, i3, i4, p[0], p[1], p[2] * self.scale_factor))
示例#11
0
 def addBondAngleTerm(self, data, angle, object, global_data):
     if not self.arguments[1]:
         return
     a1 = angle.a1
     a2 = angle.a2
     ca = angle.ca
     i1 = a1.index
     i2 = a2.index
     ic = ca.index
     global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     tc = global_data.atom_type[ca]
     try:
         p = self.dataset.bondAngleParameters(t1, tc, t2)
     except KeyError:
         raise KeyError('No parameters for angle ' + `a1` +
                         '--' + `ca` + '--' + `a2`)
     if p is not None:
         v1 = a1.position()-ca.position()
         v2 = a2.position()-ca.position()
         angle = v1.angle(v2)
         data.add('angles', (i1, ic, i2, angle) + p[1:])
示例#12
0
 def addBondAngleTerm(self, data, angle, object, global_data):
     if not self.arguments[1]:
         return
     a1 = angle.a1
     a2 = angle.a2
     ca = angle.ca
     i1 = a1.index
     i2 = a2.index
     ic = ca.index
     global_data.add('excluded_pairs', Utility.normalizePair((i1, i2)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     tc = global_data.atom_type[ca]
     try:
         p = self.dataset.bondAngleParameters(t1, tc, t2)
     except KeyError:
         raise KeyError('No parameters for angle ' + a1 +
                         '--' + ca + '--' + a2)
     if p is not None:
         v1 = a1.position()-ca.position()
         v2 = a2.position()-ca.position()
         angle = v1.angle(v2)
         data.add('angles', (i1, ic, i2, angle) + p[1:])
示例#13
0
 def addDihedralTerm(self, data, dihedral, object, global_data):
     if not self.arguments[2]:
         return
     a1 = dihedral.a1
     a2 = dihedral.a2
     a3 = dihedral.a3
     a4 = dihedral.a4
     i1 = a1.index
     i2 = a2.index
     i3 = a3.index
     i4 = a4.index
     global_data.add('1_4_pairs', Utility.normalizePair((i1, i4)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     t3 = global_data.atom_type[a3]
     t4 = global_data.atom_type[a4]
     terms = self.dataset.dihedralParameters(t1, t2, t3, t4)
     if terms is not None:
         v1 = a1.position()-a2.position()
         v2 = a2.position()-a3.position()
         v3 = a4.position()-a3.position()
         a = v1.cross(v2).normal()
         b = v3.cross(v2).normal()
         cos = a*b
         sin = b.cross(a)*v2/v2.length()
         dihedral = Transformation.angleFromSineAndCosine(sin, cos)
         if dihedral > N.pi:
             dihedral -= 2.*N.pi
         for p in terms:
             if p[2] != 0.:
                 mult = p[0]
                 phase = N.fmod(N.pi-mult*dihedral, 2.*N.pi)
                 if phase < 0.:
                     phase += 2.*N.pi
                 data.add('dihedrals', (i1, i2, i3, i4,
                                        p[0], phase) + p[2:])
示例#14
0
 def addDihedralTerm(self, data, dihedral, object, global_data):
     if not self.arguments[2]:
         return
     a1 = dihedral.a1
     a2 = dihedral.a2
     a3 = dihedral.a3
     a4 = dihedral.a4
     i1 = a1.index
     i2 = a2.index
     i3 = a3.index
     i4 = a4.index
     global_data.add('1_4_pairs', Utility.normalizePair((i1, i4)))
     t1 = global_data.atom_type[a1]
     t2 = global_data.atom_type[a2]
     t3 = global_data.atom_type[a3]
     t4 = global_data.atom_type[a4]
     terms = self.dataset.dihedralParameters(t1, t2, t3, t4)
     if terms is not None:
         v1 = a1.position()-a2.position()
         v2 = a2.position()-a3.position()
         v3 = a4.position()-a3.position()
         a = v1.cross(v2).normal()
         b = v3.cross(v2).normal()
         cos = a*b
         sin = b.cross(a)*v2/v2.length()
         dihedral = Transformation.angleFromSineAndCosine(sin, cos)
         if dihedral > N.pi:
             dihedral -= 2.*N.pi
         for p in terms:
             if p[2] != 0.:
                 mult = p[0]
                 phase = N.fmod(N.pi-mult*dihedral, 2.*N.pi)
                 if phase < 0.:
                     phase += 2.*N.pi
                 data.add('dihedrals', (i1, i2, i3, i4,
                                        p[0], phase) + p[2:])