Пример #1
0
    def add_mol_itp(self, mol_itp_file):
        """Add a molecule itp in the topologie itp_list.
        """
        fullname = (mol_itp_file.split("/")[-1])
        include = fullname.split(".")[0]
        path = os_command.full_path_and_check(mol_itp_file)
        mol_itp = Itp(name=include, fullname=fullname, path=path)

        # 1. Get new mol name:
        mol_name_list = []
        for top_mol in mol_itp.top_mol_list:
            mol_name_list.append(top_mol.name)

        # 2. Check if it already present
        present = False
        for itp in self.itp_list:
            for top_mol in itp.top_mol_list:
                if top_mol.name in mol_name_list:
                    present = True
                    break
            if present:
                break

        # Add the itp if not present
        if not present:
            self.itp_list.append(mol_itp)
Пример #2
0
def extract_itp_atomtypes(itp_in, itp_atomtypes_out):

    field = None
    atom_types_list = "[ atomtypes ]\n"

    with open(itp_in) as itpfile:
        for line in itpfile:

            if line.startswith("["):
                # Remove space and [ ]
                field = line.strip()[1:-1].strip()
                # print(field)
                continue
            if field == 'atomtypes':
                atom_types_list += line

    filout = open(itp_atomtypes_out, "w")
    filout.write(atom_types_list)
    filout.close()

    # Read and write itp to remove the [ atomtypes ] part
    fullname = (itp_in.split("/")[-1])
    include = fullname.split(".")[0]
    path = os_command.full_path_and_check(itp_in)

    top_mol = gmx.Itp(name=include, fullname=fullname, path=path)
    top_mol.write_file(path)
Пример #3
0
def make_amber_top_mol_rdkit(pdb_in,
                             res_name,
                             smile,
                             charge_model="bcc",
                             atom_type="gaff",
                             remove_h=True):

    full_coor = pdb_manip.Coor(pdb_in)
    # Select coor:
    mol_coor = full_coor.select_part_dict(selec_dict={'res_name': [res_name]})

    # Change first residue to 1, as it is the res from rdkit output
    res_list = mol_coor.get_attribute_selection(attribute='res_num')
    index_list = mol_coor.get_index_selection(
        selec_dict={'res_num': [res_list[0]]})
    mol_coor.change_index_pdb_field(index_list, change_dict={'res_num': 1})

    # Remove hydrogens:
    if remove_h:
        to_del_list = []
        for atom_num, atom in mol_coor.atom_dict.items():
            if atom['name'].startswith('H'):
                to_del_list.append(atom_num)
        mol_coor.del_atom_index(to_del_list)

    mol_coor.write_pdb(res_name + '.pdb', check_file_out=False)

    # Add hydrogens:
    # add_hydrogen(res_name+'.pdb', res_name+'_h.pdb')
    charge = add_hydrogen_rdkit(res_name + '.pdb', smile, res_name + '_h.pdb')

    # Get only one molecule
    mol_h_coor = pdb_manip.Coor(res_name + '_h.pdb')
    res_list = mol_h_coor.get_attribute_selection(attribute='uniq_resid')
    mol_uniq_coor = mol_h_coor.select_part_dict(
        selec_dict={'uniq_resid': [res_list[0]]})
    # Save coordinates:
    mol_uniq_coor.write_pdb(res_name + '_h_unique.pdb', check_file_out=False)

    # Compute topologie with acpype:
    gmxsys = acpype(res_name + '_h_unique.pdb',
                    res_name,
                    net_charge=charge,
                    charge_model="bcc",
                    atom_type="gaff")

    return ({
        'GmxSys': gmxsys,
        'coor': os_command.full_path_and_check(res_name + '_h.pdb'),
        'num': len(res_list)
    })
Пример #4
0
def make_amber_top_mol(pdb_in,
                       res_name,
                       charge,
                       charge_model="bcc",
                       atom_type="gaff",
                       remove_h=True):

    full_coor = pdb_manip.Coor(pdb_in)
    # Select coor:
    mol_coor = full_coor.select_part_dict(selec_dict={'res_name': [res_name]})

    # Remove hydrogens:
    if remove_h:
        to_del_list = []
        for atom_num, atom in mol_coor.atom_dict.items():
            if atom['name'][0] == 'H':
                to_del_list.append(atom_num)
        mol_coor.del_atom_index(to_del_list)

    mol_coor.write_pdb(res_name + '.pdb')

    # Add hydrogens:
    add_hydrogen(res_name + '.pdb', res_name + '_h.pdb')

    # Get only one molecule
    mol_h_coor = pdb_manip.Coor(res_name + '_h.pdb')
    res_list = mol_h_coor.get_attribute_selection(attribute='uniq_resid')
    mol_uniq_coor = mol_h_coor.select_part_dict(
        selec_dict={'uniq_resid': [res_list[0]]})
    # Save coordinates:
    mol_uniq_coor.write_pdb(res_name + '_h_unique.pdb')

    # Compute topologie with acpype:
    gmxsys = acpype(res_name + '_h_unique.pdb',
                    res_name,
                    net_charge=charge,
                    charge_model="bcc",
                    atom_type="gaff")

    return ({
        'GmxSys': gmxsys,
        'coor': os_command.full_path_and_check(res_name + '_h.pdb'),
        'num': len(res_list)
    })
Пример #5
0
    def __init__(self, top_in):

        self.path = os_command.full_path_and_check(top_in)
        self.forcefield = None
        self.itp_list = []
        self.mol_comp = []
        self.name = ""
        self.folder = os_command.get_directory(top_in)
        self.include_itp = False
        # Intermolecular restraints (only for Free ener):
        self.inter_interact = False
        self.inter_bond_list = []
        self.inter_angl_list = []
        self.inter_dihe_list = []

        self.read_file(top_in)
        if self.include_itp:
            logger.info("Rewrite topologie: {}".format(top_in))
            self.write_file(top_in)
Пример #6
0
    def add_atomtypes(self, new_atomtypes):
        """ Add atomtypes in a topologie.

        :param new_atomtypes: path of the atomtype itp file
        :type new_atomtypes: str

        """

        # check if and atomtypes file exists:
        # self.display()
        atom_type = False
        for itp_file in self.get_include_no_posre_file_list():
            if itp_file.split("/")[-1].endswith('atomtypes.itp'):
                # print('atomtypes file present', itp_file)
                atom_type = True
                atomtype_path = itp_file
                break

        # If it doesn't exist create it
        if not atom_type:
            fullname = (new_atomtypes.split("/")[-1])
            include = fullname.split(".")[0]
            path = os_command.full_path_and_check(new_atomtypes)
            atomtype_itp = Itp(name=include, fullname=fullname, path=path)

            self.itp_list = [atomtype_itp] + self.itp_list
        # If it does exist add the new atomtypes in the first one:
        else:
            # First extract old atom types:
            field = None
            atom_dict = {}
            name_list = []
            with open(atomtype_path) as file:
                for line in file:
                    if line.strip().startswith("["):
                        # Remove space and [ ], remove also comments
                        field = line.replace(" ", "").split("]")[0][1:]
                        continue

                    if (line[0] != ";" and line[0] != "#"
                            and line.strip() != ""):
                        # Remove commentary in the line
                        line_comment = line.split(';')
                        line_list = line_comment[0].split()

                        if field == 'atomtypes':
                            name_list.append(line_list[0])
                            name, bond_type, mass, charge, ptype, sigma, \
                                epsilon = line_list[:7]
                            atom_dict[name] = {
                                'bond_type': bond_type,
                                'mass': float(mass),
                                'charge': float(charge),
                                'ptype': ptype,
                                'sigma': float(sigma),
                                'epsilon': float(epsilon)
                            }
                            name_list.append(name)

            # Second extract new atom types and
            # check if they are already present:
            field = None
            new_atom_dict = {}
            with open(new_atomtypes) as file:
                for line in file:
                    if line.strip().startswith("["):
                        # Remove space and [ ], remove also comments
                        field = line.replace(" ", "").split("]")[0][1:]
                        continue

                    if (line[0] != ";" and line[0] != "#"
                            and line.strip() != ""):
                        # Remove commentary in the line
                        line_comment = line.split(';')
                        line_list = line_comment[0].split()

                        if field == 'atomtypes':
                            name, bond_type, mass, charge, ptype, sigma, \
                                epsilon = line_list[:7]
                            local_dict = {
                                'bond_type': bond_type,
                                'mass': float(mass),
                                'charge': float(charge),
                                'ptype': ptype,
                                'sigma': float(sigma),
                                'epsilon': float(epsilon)
                            }
                            if name not in name_list:
                                new_atom_dict[name] = local_dict
                            else:
                                # Check if the new values are the same:
                                if local_dict != atom_dict[name]:
                                    logger.warning(
                                        'Atom types parameters for {} are '
                                        'different in {} and {}. Only one '
                                        'version is kept !!!'.format(
                                            name, atomtype_path,
                                            new_atomtypes))

            # Finally append the new param in the old one
            with open(atomtype_path, 'a') as file:
                for name, atom_dict in new_atom_dict.items():
                    file.write(' {:3}      {:3}         {:.5f}  {:.5f}'
                               '   {}     {:.5e}   {:.5e}\n'.format(
                                   name, atom_dict['bond_type'],
                                   atom_dict['mass'], atom_dict['charge'],
                                   atom_dict['ptype'], atom_dict['sigma'],
                                   atom_dict['epsilon']))