#  Copyright (C) 2021 The authors of Py-ChemShell
#
#  This file is part of Py-ChemShell.
#
#  Py-ChemShell is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation, either version 3 of the
#  License, or (at your option) any later version.
#
#  Py-ChemShell is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with Py-ChemShell.  If not, see
#  <http://www.gnu.org/licenses/>.

__author__ = 'You Lu <you.lu@stfc.ukri.org>'
__date__ = 12.2021

from ..dl_py2f.utils import miscutils
from sys import stdout

@miscutils.time
def takeSnapshots(fragObj, dcd='_namd.dcd',
                           xst='_namd.xst',
                           pbc_wrap='non-solvent',
                           pbc_wrap_centre=-1,
                           nsnapshots=20,
                           ff='charmm'):

    from ..data       import forcefield
    from ..interfaces import namd
    from ..tasks      import md

    indices_to_wrap = fragObj.selectByCommonNames(pbc_wrap, ff=ff)

    namdObj = namd.NAMD(frag=fragObj,
                        xst=xst,
                       )
   
    mdObj = md.MD(theory=namdObj,
                  dcd=dcd,
                  pbc_wrap=indices_to_wrap,
                  nsnapshots=nsnapshots,
                 )
   
    mdObj.takeSnapshots(pbc_wrap_centre=pbc_wrap_centre)
