Пример #1
0
    def assign_dtypes(self, s):
        """pysimm.forcefield.Pcff.assign_dtypes

        Pcff specific dihedral typing rules.
        Requires :class:`~pysimm.system.System` object :class:`~pysimm.system.Particle` objects have bonds, type and type.name defined.
        *** use after assign_ptypes ***

        Args:
            s: :class:`~pysimm.system.System`

        Returns:
            None
        """
        all_types = set()
        s.dihedral_style = self.dihedral_style
        for b in s.bonds:
            for p1 in b.a.bonded_to:
                for p2 in b.b.bonded_to:
                    if p1 is b.b or p2 is b.a:
                        continue
                    unique = True
                    for d in s.dihedrals:
                        if ((d.a is p1 and d.b is b.a and
                             d.c is b.b and d.d is p2) or
                                (d.a is p2 and d.b is b.b and
                                 d.c is b.a and d.d is p1)):
                            unique = False
                    if unique:
                        p1_name = p1.type.eq_dihedral or p1.type.name
                        a_name = b.a.type.eq_dihedral or b.a.type.name
                        b_name = b.b.type.eq_dihedral or b.b.type.name
                        p2_name = p2.type.eq_dihedral or p2.type.name
                        dt = self.dihedral_types.get('%s,%s,%s,%s'
                                                     % (p1_name, a_name,
                                                        b_name, p2_name))
                        if dt:
                            if len(dt) == 1:
                                dt = dt[0]
                            else:
                                index = 0
                                x = 5
                                for i in range(len(dt)):
                                    if dt[i].name.count('X') < x:
                                        index = i
                                        x = dt[i].name.count('X')
                                dt = dt[index]
                            if compare('%s,%s,%s,%s' % (p1_name, a_name,
                                                        b_name, p2_name),
                                       dt.name, order=True):
                                all_types.add(dt)
                                s.dihedrals.add(Dihedral(type_name=dt.name,
                                                         a=p1, b=b.a,
                                                         c=b.b, d=p2))
                            elif compare('%s,%s,%s,%s' % (p2_name, b_name,
                                                          a_name, p1_name),
                                         dt.name, order=True):
                                all_types.add(dt)
                                s.dihedrals.add(Dihedral(type_name=dt.name,
                                                         a=p2, b=b.b,
                                                         c=b.a, d=p1))
                            else:
                                print('cannot distinguish between forward/'
                                      'backward for %s,%s,%s,%s'
                                      % (p1.type.name,
                                         b.a.type.name,
                                         b.b.type.name,
                                         p2.type.name))
                        else:
                            print ('I cant type this dihedral %s,%s,%s,%s'
                                   % (p1_name, a_name, b_name, p2_name))

        for dt in all_types:
            dt = dt.copy()
            s.dihedral_types.add(dt)

        for d in s.dihedrals:
            dt = s.dihedral_types.get(d.type_name)
            if dt:
                d.type = dt[0]
Пример #2
0
    def assign_atypes(self, s):
        """pysimm.forcefield.Pcff.assign_atypes

        Pcff specific angle typing rules.
        Requires :class:`~pysimm.system.System` object :class:`~pysimm.system.Particle` objects have bonds, type and type.name defined.
        *** use after assign_ptypes ***

        Args:
            s: :class:`~pysimm.system.System`

        Returns:
            None
        """
        all_types = set()
        s.angle_style = self.angle_style
        s.add_particle_bonding()
        for p in s.particles:
            for p1 in p.bonded_to:
                for p2 in p.bonded_to:
                    if p1 is not p2:
                        unique = True
                        for a in s.angles:
                            if ((a.a is p1 and a.b is p and a.c is p2) or
                                    (a.a is p2 and a.b is p and a.c is p1)):
                                unique = False
                        if unique:
                            at = self.angle_types.get('%s,%s,%s'
                                                      % (p1.type.name,
                                                         p.type.name,
                                                         p2.type.name))
                            if at:
                                if compare('%s,%s,%s' % (p1.type.name,
                                                         p.type.name,
                                                         p2.type.name),
                                           at[0].name, order=True):
                                    s.angles.add(Angle(type_name=at[0].name,
                                                       a=p1, b=p, c=p2))
                                    all_types.add(at[0])
                                elif compare('%s,%s,%s' % (p2.type.name,
                                                           p.type.name,
                                                           p1.type.name),
                                             at[0].name, order=True):
                                    s.angles.add(Angle(type_name=at[0].name,
                                                       a=p2, b=p, c=p1))
                                    all_types.add(at[0])
                                else:
                                    print('cannot distinguish between forward/'
                                          'backward for %s,%s,%s'
                                          % (p1.type.name,
                                             p.type.name,
                                             p2.type.name))
                            else:
                                print('I cant type this angle %s,%s,%s'
                                      % (p1.type.name,
                                         p.type.name,
                                         p2.type.name))

        for at in all_types:
            at = at.copy()
            s.angle_types.add(at)

        for a in s.angles:
            at = s.angle_types.get(a.type_name)
            if at:
                a.type = at[0]