UB CE 530 - Object Oriented Programming of Molecular Simulation

Unformatted text preview:

Object Oriented Programming of Molecular SimulationObject-Oriented ProgrammingWhat is an Object?Molecular Simulation APISimulationSpaceControllerIntegratorPhaseMeterSpeciesPotentialDisplayDeviceExampleObject Oriented Programming of Molecular SimulationIn this section we introduce concepts of object-oriented programming in the context of molecular simulation. Object-oriented programming (OOP) is very different conceptually from the approach taken in procedural languages such as Fortran or C, and it takes a certain shift in one’s thinking to embrace and implement true OOP constructs. We say “true” OOP constructs because any OOP language can be implemented in a procedural fashion; the most basic constructs and operations in OOP languages are the same as those in procedural languages: loops, if-else statements, assignments, arithmetic operations, etc. OOP languages can be used to write procedural programs, but of course this is not object-oriented programming. Object-oriented programming presents several benefits, mostly related to the ease with which one can use and extend existing code to do new things. Also, object oriented programs generally are easier to understand than procedural programs (assuming one is comfortable with the OOP concept itself), in part because the programs are forced to be structured well, but also because the mapping of the code onto the physical problem being modeled is more obvious. There is often a performance price to pay for this clarity of code, in that a tightly constructed procedural code can complete a calculation more quickly than a comparable OOP code. However, the performance advantage of procedural languages can be offset by the programming time needed to implement them. One can even imagine situations where the ease of OOP coding permits a complex but efficient algorithm to be implemented in a situation where one would not want to take thetrouble to do the same algorithm procedurally.Regardless, our primary aim in this course is to teach molecular simulation concepts, with computational performance arising as an issue mainly via the structure of algorithms, not their implementation. In this situation the benefits of OOP suit our needs perfectly: we would like to permit the student to construct a wide variety of interesting molecular simulations, and we would like to make the programming constructs as clear aspossible. Thus we spend time now introducing some of the basic ideas of object-orientedprogramming, and how they can be applied to molecular simulation. The two most popular OOP languages in present use are C++ and Java. C++ is (in ways) a more powerful language, but it is more difficult to use than Java. Java is a good language for our purposes because it is better designed, easier on the programmer, and lets us write programs (small applications, or applets) that we can make available to run via a Web browser. All of the example simulations and other applets used in this course are written in Java. We anticipate that the reader does not have any background in Java, but it is not our aim to give a comprehensive presentation of the language. Instead, will here present the mostelementary terms and concepts, and teach the rest by example as we move on to molecular simulation. This way the reader is guaranteed to learn only that which is relevant to the course, and will always see a direct example of the use of any new Java construct. The novice student must wade through a seemingly endless set of new words and ideas, but eventually the new things are repeated enough that they become old andfamiliar. It is worth taking the effort to get through this and see how powerful the language can be for you.After a very brief introduction to OOP, we present an object-oriented framework for molecular simulation. This framework has been partially implemented by us in Java, andthis library of codes will be used as a basis for instruction and programming of simulationmethods throughout the rest of this course. In this chapter we therefore take some time tointroduce this molecular simulation library, or Application Programming Interface (API).Object-Oriented ProgrammingObject-oriented programming is computer programming accomplished through the actions and interactions of objects. In OOP languages (or at least in Java), everything is an object. Nothing is done, no data exist, in the absence of some object that defines the data and the action. Usually objects are defined to correspond to some physical or conceptual element in the problem being modeled. For example, a molecular simulation program will use Atom objects as part of its coding. Such an object holds particular data,such as its position and momentum, and it performs (or can have performed on it) certain actions, such as being moved. Once an Atom is designed and coded, it can be re-used in different situations, such as in molecular dynamics or Monte Carlo simulations. In this way good OOP design promotes re-use of existing code.There is no unique way to implement an OOP for a given problem, and it is a significant intellectual challenge to construct an OOP design that promotes its re-use and, more importantly, extension to unanticipated types of physical problems. A good design requires a thorough understanding of the problem being modeled, so that the right decisions can be made about how to carve out the different objects and how they should interact.What is an Object?An object is a fancy variable. It is a collection of data and actions that can be referred to and passed around as a complete entity, much as simple real or integer values can be assigned to variables or passed to subroutines in procedural languages. By swapping in and out whole objects (as simply as assigning to a single variable), one can completely change the behavior of a simulation (changing it from molecular dynamics to Monte Carlo, for example).Every object in a program has a type or class associated with it. This typing of objects is little different than the typing of primitives as real, integer, or boolean. Unlike these primitives, new classes can be defined as needed to solve a particular problem. Indeed most of OOP involves the defining of new classes. Classes differ in the number and type of data they hold, and the actions they perform on these data. Unlike primitive data types, objects must be constructed or instantiated before they can be used. This is the process of setting


View Full Document

UB CE 530 - Object Oriented Programming of Molecular Simulation

Documents in this Course
Load more
Download Object Oriented Programming of Molecular Simulation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Object Oriented Programming of Molecular Simulation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object Oriented Programming of Molecular Simulation 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?