Пример #1
0
    def get_chimera(self, session, coordsets=False, filereader=None):
        """returns a chimerax equivalent of self"""
        struc = AtomicStructure(session, name=self.name)
        struc.comment = self.comment

        self.update_chix(struc)

        if coordsets and filereader is not None and filereader.all_geom is not None:
            #make a trajectory
            #each list of atoms in filereader.all_geom is a frame in the trajectory
            #replace previous coordinates
            #this matters when a filereader is given because the
            #geometry created from a filereader (which was probably passed as geom)
            #is the last geometry in the log or xyz file
            xyzs = self.all_geom_coordsets(filereader)
            struc.add_coordsets(xyzs, replace=True)
            struc.active_coordset_id = len(xyzs)

        # if it's a frequency file, draw TS bonds for imaginary modes
        if filereader is not None and "frequency" in filereader.other:
            for mode in filereader.other["frequency"].data:
                if mode.frequency < 0:
                    max_disp = max(np.linalg.norm(x) for x in mode.vector)
                    cur_coords = self.coords
                    coord_forward = self.coords + (0.2 /
                                                   max_disp) * mode.vector
                    coord_reverse = self.coords - (0.2 /
                                                   max_disp) * mode.vector
                    forward_connectivity = np.zeros(
                        (len(self.atoms), len(self.atoms)))
                    reverse_connectivity = np.zeros(
                        (len(self.atoms), len(self.atoms)))
                    self.update_geometry(coord_forward)
                    self.refresh_connected()
                    for i, atom1 in enumerate(self.atoms):
                        for j, atom2 in enumerate(self.atoms[:i]):
                            if atom1 in atom2.connected:
                                forward_connectivity[i, j] = 1
                                forward_connectivity[j, i] = 1

                    self.update_geometry(coord_reverse)
                    self.refresh_connected()
                    for i, atom1 in enumerate(self.atoms):
                        for j, atom2 in enumerate(self.atoms[:i]):
                            if atom1 in atom2.connected:
                                reverse_connectivity[i, j] = 1
                                reverse_connectivity[j, i] = 1

                    changes = forward_connectivity - reverse_connectivity
                    for i, atom1 in enumerate(self.atoms):
                        for j, atom1 in enumerate(self.atoms[:i]):
                            if changes[i, j] != 0:
                                sel = _FauxAtomSelection(
                                    atoms=(struc.atoms[i], struc.atoms[j]))
                                tsbond(session, sel)

                    self.update_geometry(cur_coords)

        return struc
Пример #2
0
    def get_chimera(self, session, coordsets=False, filereader=None):
        """returns a chimerax equivalent of self"""
        struc = AtomicStructure(session, name=self.name)
        struc.comment = self.comment

        self.update_chix(struc)

        if coordsets and filereader is not None and filereader.all_geom is not None:
            #make a trajectory
            #each list of atoms in filereader.all_geom is a frame in the trajectory
            #replace previous coordinates
            #this matters when a filereader is given because the
            #geometry created from a filereader (which was probably passed as geom)
            #is the last geometry in the log or xyz file
            xyzs = self.all_geom_coordsets(filereader)
            struc.add_coordsets(xyzs, replace=True)
            struc.active_coordset_id = len(xyzs)

        # if it's a frequency file, draw TS bonds for imaginary modes
        if filereader is not None and "frequency" in filereader.other:
            for mode in filereader.other["frequency"].data:
                if mode.frequency < 0:
                    max_disp = max(np.linalg.norm(x) for x in mode.vector)
                    cur_coords = self.coords
                    coord_forward = self.coords + (0.2 /
                                                   max_disp) * mode.vector
                    coord_reverse = self.coords - (0.2 /
                                                   max_disp) * mode.vector
                    forward_connectivity = np.zeros(
                        (len(self.atoms), len(self.atoms)))
                    reverse_connectivity = np.zeros(
                        (len(self.atoms), len(self.atoms)))
                    self.update_geometry(coord_forward)
                    self.refresh_connected()
                    for i, atom1 in enumerate(self.atoms):
                        for j, atom2 in enumerate(self.atoms[:i]):
                            if atom1 in atom2.connected:
                                forward_connectivity[i, j] = 1
                                forward_connectivity[j, i] = 1

                    self.update_geometry(coord_reverse)
                    self.refresh_connected()
                    for i, atom1 in enumerate(self.atoms):
                        for j, atom2 in enumerate(self.atoms[:i]):
                            if atom1 in atom2.connected:
                                reverse_connectivity[i, j] = 1
                                reverse_connectivity[j, i] = 1

                    changes = forward_connectivity - reverse_connectivity
                    for i, atom1 in enumerate(self.atoms):
                        for j, atom1 in enumerate(self.atoms[:i]):
                            if changes[i, j] != 0:
                                sel = _FauxAtomSelection(
                                    atoms=(struc.atoms[i], struc.atoms[j]))
                                tsbond(session, sel)

                    self.update_geometry(cur_coords)

        if filereader is not None and "Mulliken Charges" in filereader.other:
            for atom, charge in zip(struc.atoms,
                                    filereader.other["Mulliken Charges"]):
                atom.mullikenCharge = charge
                atom.charge = charge

                if not any(attr[0] == "mullikenCharge"
                           for attr in atom.custom_attrs):
                    atom.register_attr(session,
                                       "mullikenCharge",
                                       "seqcrow ResidueCollection.get_chimera",
                                       attr_type=float)
                if not any(attr[0] == "charge" for attr in atom.custom_attrs):
                    atom.register_attr(session,
                                       "charge",
                                       "seqcrow ResidueCollection.get_chimera",
                                       attr_type=float)

        if filereader is not None and "NPA Charges" in filereader.other:
            for atom, charge in zip(struc.atoms,
                                    filereader.other["NPA Charges"]):
                atom.npaCharge = charge
                atom.charge = charge

                if not any(attr[0] == "npaCharge"
                           for attr in atom.custom_attrs):
                    atom.register_attr(session,
                                       "npaCharge",
                                       "seqcrow ResidueCollection.get_chimera",
                                       attr_type=float)
                if not any(attr[0] == "charge" for attr in atom.custom_attrs):
                    atom.register_attr(session,
                                       "charge",
                                       "seqcrow ResidueCollection.get_chimera",
                                       attr_type=float)

        if filereader is not None and "Nuclear ZEff" in filereader.other:
            for atom, zeff in zip(struc.atoms,
                                  filereader.other["Nuclear ZEff"]):
                atom.Zeff = zeff

                if not any(attr[0] == "Zeff" for attr in atom.custom_attrs):
                    atom.register_attr(session,
                                       "Zeff",
                                       "seqcrow ResidueCollection.get_chimera",
                                       attr_type=float)

        if filereader is not None and "Nuclear spins" in filereader.other:
            for atom, spin in zip(struc.atoms,
                                  filereader.other["Nuclear spins"]):
                atom.nuclearSpin = spin

                if not any(attr[0] == "nuclearSpin"
                           for attr in atom.custom_attrs):
                    atom.register_attr(session,
                                       "nuclearSpin",
                                       "seqcrow ResidueCollection.get_chimera",
                                       attr_type=int)

        if filereader is not None:
            if any(attr[0] == "aarontools_filereader"
                   for attr in struc.custom_attrs):
                struc.register_attr(
                    session,
                    "filereader",
                    "SEQCROW",
                    attr_type=FileReader,
                )

            struc.filereader = filereader

        return struc