From 4ad3d382ad4e45961e1105254208f6e54008deeb Mon Sep 17 00:00:00 2001 From: Joe Jordan Date: Tue, 7 Aug 2018 15:13:18 +0200 Subject: [PATCH] Fix pdb2gmx -chainsep Fixes #2577 This patch makes readConfAndAtoms public and has pdb2gmx call it directly. Previously pdb2gmx called readConfAndTopology, which then called readConfAndAtoms and then tpx_make_chain_identifiers, the latter of which is suspected of being broken, as documented in the TODO added here. Change-Id: I1b47e1743f6accf77ae67d232eb2c815edcff970 --- src/gromacs/fileio/confio.cpp | 9 +++++---- src/gromacs/fileio/confio.h | 21 ++++++++++++++++++++- src/gromacs/gmxpreprocess/pdb2gmx.cpp | 23 +++++++++-------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/gromacs/fileio/confio.cpp b/src/gromacs/fileio/confio.cpp index fdc861341e..36cd7250be 100644 --- a/src/gromacs/fileio/confio.cpp +++ b/src/gromacs/fileio/confio.cpp @@ -237,6 +237,7 @@ static void get_stx_coordnum(const char *infile, int *natoms) } } +// TODO molecule index handling is suspected of being broken here static void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols) { /* We always assign a new chain number, but save the chain id characters @@ -349,10 +350,10 @@ static void read_stx_conf(const char *infile, } } -static void readConfAndAtoms(const char *infile, - t_symtab *symtab, char **name, t_atoms *atoms, - int *ePBC, - rvec **x, rvec **v, matrix box) +void readConfAndAtoms(const char *infile, + t_symtab *symtab, char **name, t_atoms *atoms, + int *ePBC, + rvec **x, rvec **v, matrix box) { int natoms; get_stx_coordnum(infile, &natoms); diff --git a/src/gromacs/fileio/confio.h b/src/gromacs/fileio/confio.h index be8b299669..afd6b166f6 100644 --- a/src/gromacs/fileio/confio.h +++ b/src/gromacs/fileio/confio.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -49,6 +49,7 @@ extern "C" { struct gmx_mtop_t; struct t_atoms; +struct t_symtab; struct t_topology; void write_sto_conf_indexed(const char *outfile, const char *title, @@ -86,6 +87,24 @@ void readConfAndTopology(const char *infile, int *ePBC, rvec **x, rvec **v, matrix box); +/*! \brief Read a configuration from a structure file. + * + * This should eventually be superseded by TopologyInformation + * + * \param[in] infile Input file name + * \param[out] symtab The symbol table + * \param[out] name The title of the molecule, e.g. from pdb TITLE record + * \param[out] atoms The global t_atoms struct + * \param[out] ePBC Enum reporting the type of PBC + * \param[in,out] x Coordinates will be stored when *x!=NULL + * \param[in,out] v Velocities will be stored when *v!=NULL + * \param[out] box Box dimensions + */ +void readConfAndAtoms(const char *infile, + t_symtab *symtab, char **name, t_atoms *atoms, + int *ePBC, + rvec **x, rvec **v, matrix box); + /*! \brief Read a configuration and, when available, a topology from a tpr or structure file. * * Deprecated, superseded by readConfAndTopology(). diff --git a/src/gromacs/gmxpreprocess/pdb2gmx.cpp b/src/gromacs/gmxpreprocess/pdb2gmx.cpp index df98f0905c..2a1a219cf1 100644 --- a/src/gromacs/gmxpreprocess/pdb2gmx.cpp +++ b/src/gromacs/gmxpreprocess/pdb2gmx.cpp @@ -528,25 +528,19 @@ static void write_posres(char *fn, t_atoms *pdba, real fc) gmx_fio_fclose(fp); } -static int read_pdball(const char *inf, const char *outf, char *title, +static int read_pdball(const char *inf, const char *outf, char **title, t_atoms *atoms, rvec **x, int *ePBC, matrix box, gmx_bool bRemoveH, t_symtab *symtab, gmx_residuetype_t *rt, const char *watres, gmx_atomprop_t aps, gmx_bool bVerbose) /* Read a pdb file. (containing proteins) */ { - int natom, new_natom, i; + int natom, new_natom, i; /* READ IT */ printf("Reading %s...\n", inf); - t_topology *top; - snew(top, 1); - read_tps_conf(inf, top, ePBC, x, nullptr, box, FALSE); - strncpy(title, *top->name, STRLEN); - title[STRLEN-1] = '\0'; - *atoms = top->atoms; - sfree(top); - natom = atoms->nr; + readConfAndAtoms(inf, symtab, title, atoms, ePBC, x, nullptr, box); + natom = atoms->nr; if (atoms->pdbinfo == nullptr) { snew(atoms->pdbinfo, atoms->nr); @@ -576,7 +570,7 @@ static int read_pdball(const char *inf, const char *outf, char *title, printf("Read"); if (title[0]) { - printf(" '%s',", title); + printf(" '%s',", *title); } printf(" %d atoms\n", natom); @@ -595,7 +589,7 @@ static int read_pdball(const char *inf, const char *outf, char *title, if (outf) { - write_sto_conf(outf, title, atoms, *x, nullptr, *ePBC, box); + write_sto_conf(outf, *title, atoms, *x, nullptr, *ePBC, box); } return natom; @@ -1388,7 +1382,7 @@ int gmx_pdb2gmx(int argc, char *argv[]) gmx_residuetype_t*rt; const char *top_fn; char itp_fn[STRLEN], posre_fn[STRLEN], buf_fn[STRLEN]; - char molname[STRLEN], title[STRLEN]; + char molname[STRLEN]; char *c, forcefield[STRLEN], ffdir[STRLEN]; char ffname[STRLEN], suffix[STRLEN], buf[STRLEN]; char *watermodel; @@ -1650,7 +1644,8 @@ int gmx_pdb2gmx(int argc, char *argv[]) } aps = gmx_atomprop_init(); - natom = read_pdball(opt2fn("-f", NFILE, fnm), opt2fn_null("-q", NFILE, fnm), title, + char *title; + natom = read_pdball(opt2fn("-f", NFILE, fnm), opt2fn_null("-q", NFILE, fnm), &title, &pdba_all, &pdbx, &ePBC, box, bRemoveH, &symtab, rt, watres, aps, bVerbose); -- 2.11.4.GIT