示例#1
0
    def import_restraints(self, verbose: bool = False) -> t.List[dict]:
        """
        This function reads in a gromos distance restraint file. TODO: Read
            in additional Settings (r0, w0, etc...)

        TODO: WE could try to read thefile in get_args to get the Error there already.
         IDEA: READ THE WHOLE TEXT IN GET ARGS AND ONLY CONVERT IT HERE. OS ALLERRORS HAPPEN IN GET ARGS

        Parameters
        ----------
        verbose

        Returns
        -------
        t.List[dict]
            returns a dict containing the atom ids for each disres. (has to be
            translated in interface_Pymol


        """

        restraint_objects = [
        ]  # Define before try_block, so we can return the empty list in case of errors
        try:
            # readFiles
            disres_file = Files.Gromos_files.disres(self.in_path)
            if verbose: print(disres_file)
            if verbose: print("READ: " + "".join(disres_file["TITLE"]))

            # Analogous new version
            for restraint in disres_file.distance_res_spec_block.RESTRAINTS:
                if verbose: print(restraint)
                atom1 = u.find_atom_by_property(self.all_atoms,
                                                restraint.atom1i)
                atom2 = u.find_atom_by_property(self.all_atoms,
                                                restraint.atom2i)
                new_restraint = Restraints.DistanceRestraint(atomA=atom1,
                                                             atomB=atom2)
                restraint_objects.append(new_restraint)

            # PRINT RESULTS
            for i_r, r in enumerate(restraint_objects):
                print('PairRestraint', str(i_r), ': Atom1_ID:',
                      str(r.atoms[0].id), 'Atom2_ID:', str(r.atoms[1].id))

        except FileNotFoundError:
            print("Error: Could not find the file: \'" + self.in_path + "\'",
                  mv=4)
        except KeyError:
            print("Error: Could not read the file: " + self.in_path, mv=4)
        except ImportError:
            print(
                "BAD ERROR: FAILED TO IMPORT THE MODULES NECESSARY FOR IMPORTING AND EXPORTING GROMOS FILES!",
                mv=4)

        if (len(restraint_objects) == 0):
            warnings.warn("Could not find any Restraint in file: " +
                          str(self.in_path))
        return restraint_objects
示例#2
0
    def import_restraints(self, verbose: bool = False) -> t.List[dict]:
        """
        This function reads in a gromos distance restraint file. TODO: Read
            in additional Settings (r0, w0, etc...)

        TODO: WE could try to read thefile in get_args to get the Error there already.
         IDEA: READ THE WHOLE TEXT IN GET ARGS AND ONLY CONVERT IT HERE. OS ALLERRORS HAPPEN IN GET ARGS

        Parameters
        ----------
        verbose

        Returns
        -------
        t.List[dict]
            returns a dict containing the atom ids for each disres. (has to be
            translated in interface_Pymol


        """

        restraint_objects = [
        ]  # Define before try_block, so we can return the empty list in case of errors
        try:
            tmp_file_content = json.load(open(self.in_path, "r"))

            # Analogous new version
            for i, restraint in tmp_file_content.items():
                if verbose: print(restraint)
                atom1 = u.find_atom_by_property(self.all_atoms,
                                                restraint['a1']['id'])
                atomRef = u.find_atom_by_property(self.all_atoms,
                                                  restraint['aR']['id'])
                new_restraint = Restraints.PositionRestraint(
                    atomA=atom1, reference_atom=atomRef)
                restraint_objects.append(new_restraint)

            # PRINT RESULTS
            for i_r, r in enumerate(restraint_objects):
                print('PositionRestraint', str(i_r), ': Atom1_ID:',
                      str(r.atoms[0].id), 'AtomR_ID:',
                      str(r.reference_atom.id))

        except FileNotFoundError:
            print("Error: Could not find the file: \'" + self.in_path + "\'",
                  mv=4)
        except KeyError:
            print("Error: Could not read the file: " + self.in_path, mv=4)
        except ImportError:
            print(
                "BAD ERROR: FAILED TO IMPORT THE MODULES NECESSARY FOR IMPORTING AND EXPORTING JSON FILES!",
                mv=4)

        if (len(restraint_objects) == 0):
            warnings.warn("Could not find any Restraint in file: " +
                          str(self.in_path))
        return restraint_objects