def _setup(self): """Setup the input files and working directory ready for simulation.""" # Create the input files... # First create a copy of the system. system = self._system.copy() # If the we are performing a free energy simulation, then check that # the system contains a single perturbable molecule. If so, then create # and write a perturbation file to the work directory. if type(self._protocol) is _Protocol.FreeEnergy: if system.nPerturbableMolecules() == 1: # Extract the perturbable molecule. pert_mol = system.getPerturbableMolecules()[0] # Write the perturbation file and get the molecule corresponding # to the lambda = 0 state. pert_mol = pert_mol._toPertFile( self._pert_file, property_map=self._property_map) self._input_files.append(self._pert_file) # Remove the perturbable molecule. system._sire_object.remove(pert_mol.number()) # Recreate the system, putting the perturbable molecule with # renamed properties first. updated_system = _System(pert_mol) + _System(system) # Copy across all of the properties from the orginal system. for prop in system._sire_object.propertyKeys(): updated_system._sire_object.setProperty( prop, system._sire_object.property(prop)) # Copy the updated system object across. system = updated_system else: raise ValueError("'BioSimSpace.Protocol.FreeEnergy' requires a single " "perturbable molecule. The system has %d" \ % system.nPerturbableMolecules()) # If this is a different protocol and the system still contains a # perturbable molecule, then we'll warn the user and simulate the # lambda = 0 state. else: if system.nPerturbableMolecules() > 0: if not "is_lambda1" in self._property_map: is_lambda1 = False _warnings.warn( "The system contains a perturbable molecule but " "this isn't a 'FreeEnergy' protocol. We will assume " "that you intend to simulate the lambda = 0 state. " "If you want to simulate the lambda = 1 state, then " "pass {'is_lambda1' : True} in the 'property_map' " "argument.") else: is_lambda1 = self._property_map["is_lambda1"] self._property_map.pop("is_lambda1") # Loop over all perturbable molecules in the system and replace them # with a regular molecule and the chosen end state. for mol in system.getPerturbableMolecules(): system.updateMolecules( mol._toRegularMolecule(property_map=self._property_map, is_lambda1=is_lambda1)) # Copy across the properties from the original system. for prop in self._system._sire_object.propertyKeys(): system._sire_object.setProperty( prop, self._system._sire_object.property(prop)) # RST file (coordinates). try: rst = _SireIO.AmberRst7(system._sire_object, self._property_map) rst.writeToFile(self._rst_file) except Exception as e: msg = "Failed to write system to 'RST7' format." if _isVerbose(): raise IOError(msg) from e else: raise IOError(msg) from None # PRM file (topology). try: prm = _SireIO.AmberPrm(system._sire_object, self._property_map) prm.writeToFile(self._top_file) except Exception as e: msg = "Failed to write system to 'PRM7' format." if _isVerbose(): raise IOError(msg) from e else: raise IOError(msg) from None # Generate the SOMD configuration file. # Skip if the user has passed a custom config. if type(self._protocol) is _Protocol.Custom: self.setConfig(self._protocol.getConfig()) else: self._generate_config() self.writeConfig(self._config_file) # Generate the dictionary of command-line arguments. self._generate_args() # Return the list of input files. return self._input_files
def _setup(self): """Setup the input files and working directory ready for simulation.""" # Create the input files... # First create a copy of the system. system = _System(self._system) # If the we are performing a free energy simulation, then check that # the system contains a single perturbable molecule. If so, then create # and write a perturbation file to the work directory. if type(self._protocol) is _Protocol.FreeEnergy: if system.nPerturbableMolecules() == 1: # Extract the perturbable molecule. pert_mol = system.getPerturbableMolecules()[0] # Write the perturbation file and get the molecule corresponding # to the lambda = 0 state. pert_mol = pert_mol._toPertFile( self._pert_file, property_map=self._property_map) self._input_files.append(self._pert_file) # Remove the perturbable molecule. system._sire_system.remove(pert_mol.number()) # Recreate the system, putting the perturbable molecule with # renamed properties first. updated_system = _System(pert_mol) + _System(system) # Copy across all of the properties from the orginal system. for prop in system._sire_system.propertyKeys(): updated_system._sire_system.setProperty( prop, system._sire_system.property(prop)) # Copy the updated system object across. system = updated_system else: raise ValueError("'BioSimSpace.Protocol.FreeEnergy' requires a single " "perturbable molecule. The system has %d" \ % system.nPerturbableMolecules()) # Extract the updated Sire system. system = system._sire_system # RST file (coordinates). try: rst = _SireIO.AmberRst7(system, self._property_map) rst.writeToFile(self._rst_file) except: raise IOError("Failed to write system to 'RST7' format.") from None # PRM file (topology). try: prm = _SireIO.AmberPrm(system, self._property_map) prm.writeToFile(self._top_file) except: raise IOError("Failed to write system to 'PRM7' format.") from None # Generate the SOMD configuration file. # Skip if the user has passed a custom config. if type(self._protocol) is _Protocol.Custom: self.setConfig(self._protocol.getConfig()) else: self._generate_config() self.writeConfig(self._config_file) # Generate the dictionary of command-line arguments. self._generate_args() # Return the list of input files. return self._input_files