summaryrefslogtreecommitdiff
path: root/cad/plugins/NanoVision-1/src/Interface/NXMoleculeSet.cpp
blob: 7292d06f05e4d5a0eaeaac236ae5a9625375932e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

// Copyright 2008 Nanorex, Inc.  See LICENSE file for details. 

#include "Nanorex/Interface/NXMoleculeSet.h"

namespace Nanorex {

unsigned int NXMoleculeSet::NextMoleculeIndex = 0;

char const *const NXMoleculeSet::groupClassificationString[NXMoleculeSet::NUM_GROUP_CLASSIFICATIONS] =
{
	"", "DnaGroup", "DnaSegment", "DnaStrand", "Block",
		"NanotubeGroup", "NanotubeSegment"
};

/* CONSTRUCTOR */
NXMoleculeSet::NXMoleculeSet(bool const& deleteOnDestruct)
	: deleteInDestructor(deleteOnDestruct),
	children(), molecules(),
	title(), classification(NONE)
{
}


/* DESTRUCTOR */
NXMoleculeSet::~NXMoleculeSet() {
	if(deleteInDestructor) {
		OBMolIterator molIter;
		for(molIter = moleculesBegin(); molIter != moleculesEnd(); ++molIter)
			delete *molIter;
		
		NXMoleculeSetIterator molSetIter;
		for(molSetIter = childrenBegin(); molSetIter != childrenEnd(); ++molSetIter)
			delete *molSetIter;
	}
}


/* FUNCTION: newMolecule */
OBMol* NXMoleculeSet::newMolecule() {
	OBMol* molecule = new OBMol();
	NXMoleculeData* moleculeData = new NXMoleculeData();
	moleculeData->SetIdx(NextMoleculeIndex);
	NextMoleculeIndex++;
	molecule->SetData(moleculeData);
	molecules.push_back(molecule);
	return molecule;
}


/* FUNCTION: getCounts */
void NXMoleculeSet::getCounts(unsigned int& moleculeCount,
							  unsigned int& atomCount,
							  unsigned int& bondCount) {
							  
	moleculeCount = atomCount = bondCount = 0;
	getCountsHelper(moleculeCount, atomCount, bondCount, this);
}


/* FUNCTION: getCountsHelper */
void NXMoleculeSet::getCountsHelper(unsigned int& moleculeCount,
									unsigned int& atomCount,
									unsigned int& bondCount,
									NXMoleculeSet* moleculeSet) {
									
	moleculeCount += moleculeSet->moleculeCount();
	OBMolIterator moleculeIter = moleculeSet->moleculesBegin();
	while (moleculeIter != moleculeSet->moleculesEnd()) {
		atomCount += (*moleculeIter)->NumAtoms();
		bondCount += (*moleculeIter)->NumBonds();
		moleculeIter++;
	}
	NXMoleculeSetIterator moleculeSetIter = moleculeSet->childrenBegin();
	while (moleculeSetIter != moleculeSet->childrenEnd()) {
		getCountsHelper(moleculeCount, atomCount, bondCount, *moleculeSetIter);
		moleculeSetIter++;
	}
}


bool NXMoleculeSet::empty(void)
{
    if(molecules.empty()) {
        list<NXMoleculeSet*>::const_iterator childrenIter;
        for(childrenIter = childrenBegin();
            childrenIter != childrenEnd();
            ++childrenIter)
        {
            NXMoleculeSet *const childMolSetPtr = *childrenIter;
            if(!childMolSetPtr->empty()) return false;
        }
        return true; // children are also empty
    }
    else return false;
}




} // Nanorex::