#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Question about _this()


    In the following code ( A molecule includes several atoms.):

    for j in range(mol.getNbAtoms()):
    mol.atoms[ j ]._this()
    mol = mol._this()

    my question is: what is the meaning of the Line 2. If _this() returns an atom, where will this atom be return?
    These codes are from a program written by other people, So I don't understand it quite well.
    Thanks for answers!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Guessing, you've shown hardly any code.

    mol is an object representing some molecule. Let's call it carbon dioxide.


    mol.getNbAtoms()

    getNbAtoms is a method of the Molecule class. It returns the number of atoms in the molecule. 3 for CO_2.

    mol.atoms is a an object with a __getitem__ method. In other words, it supports the [] indexing notation.

    mol.atoms[ 0] would return an Atom object, say, for oxygen.

    mol.atoms[1] likewise is an Atom object, say, carbon.

    mol.atoms[2] would represent another oxygen. Could be the same object as mol.atoms[0], or a different one if the simulation accounts for the state of each atom.

    _this is a method. A function that need not takes any parameters.

    Molecule._this might be different from Atom._this .


    Programming experiment. Before running the program again insert statements like

    print('mol._this')
    print(help(mol._this))
    print(''atom 0 ._this')
    print(help(mol.atoms[0]._this))
    for j in range(mol.getNbAtoms()):
    ...



    Summary: I think your interpretation of the program is incorrect. mol.atoms[j] represents the atom. Furthermore, without more code I'm clueless, this entire explanation may be an exercise in bogosity.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Guessing, you've shown hardly any code.

    mol is an object representing some molecule. Let's call it carbon dioxide.


    mol.getNbAtoms()

    getNbAtoms is a method of the Molecule class. It returns the number of atoms in the molecule. 3 for CO_2.

    mol.atoms is a an object with a __getitem__ method. In other words, it supports the [] indexing notation.

    mol.atoms[ 0] would return an Atom object, say, for oxygen.

    mol.atoms[1] likewise is an Atom object, say, carbon.

    mol.atoms[2] would represent another oxygen. Could be the same object as mol.atoms[0], or a different one if the simulation accounts for the state of each atom.

    _this is a method. A function that need not takes any parameters.

    Molecule._this might be different from Atom._this .


    Programming experiment. Before running the program again insert statements like

    print('mol._this')
    print(help(mol._this))
    print(''atom 0 ._this')
    print(help(mol.atoms[0]._this))
    for j in range(mol.getNbAtoms()):
    ...



    Summary: I think your interpretation of the program is incorrect. mol.atoms[j] represents the atom. Furthermore, without more code I'm clueless, this entire explanation may be an exercise in bogosity.
    Thanks for your patiently reply!

    Because it takes several pages to post the codes, I choose not to do that. Your guess actually makes sense.
    The Line 3 is quite clear for me. For Line 2, I expect a line like this:
    mol.atoms.append(NewAtom)
    There is no implementation of _this() in Atom class, which makes me dizzy.
    Your advice is quite useful, I will try and see what is inside _this().
    Thanks!
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    _this might be defined in a parent class which you could find via source that looks like

    class SubClass(ParentClass):


    Likely that mols.atoms is a list.

    print(type(mols.atoms)) # indicator
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo